Skip to content

Commit 235a0ce

Browse files
committed
issue2551391 - checkboxes and radiobutton inputs get wrong id's.
Actually it breaks automatic id assignment for all inputs. Inputs now get an automatic id assignment that matches the name. It can be overridden by supplting an id parameter in the call to the field() method. This is also a partial fix for issue1513369. I think it obsoletes the changes to templating.py.
1 parent d92f766 commit 235a0ce

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Fixed:
7474
- close http socket and send a 408 status when a timeout exception
7575
is handed in roundup-server. This prevents another exception
7676
caused by using a timed out socket. (John Rouillard)
77+
- issue2551391, partial fix for issue1513369. input fields were
78+
not getting id's assigned. Fixed automatic id assignment to
79+
input fields. Thinko in the code. (John Rouillard)
7780

7881
Features:
7982

roundup/cgi/templating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def _set_input_default_args(dic):
607607
# useful e.g for HTML LABELs:
608608
if 'id' not in dic:
609609
try:
610-
if dic['text'] in ('radio', 'checkbox'):
610+
if dic['type'] in ('radio', 'checkbox'):
611611
dic['id'] = '%(name)s-%(value)s' % dic
612612
else:
613613
dic['id'] = dic['name']

test/test_cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
950950
<p>deferred</p>
951951
<p>admin, anonymous</p>
952952
<p></p>
953-
<p><input name="superseder" size="30" type="text" value="5000"></p>
953+
<p><input id="superseder" name="superseder" size="30" type="text" value="5000"></p>
954954
</body>
955955
</html>
956956
""".strip ())

test/test_liveserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,9 +1503,9 @@ def test__generic_item_template_editok(self, user="admin"):
15031503
self.assertIn(b'done-cbb', f.content)
15041504

15051505
if user == 'admin':
1506-
self.assertIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
1506+
self.assertIn(b'<input id="submit_button" name="submit_button" type="submit" value="Submit Changes">', f.content)
15071507
else:
1508-
self.assertNotIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
1508+
self.assertNotIn(b'<input id="submit_button" name="submit_button" type="submit" value="Submit Changes">', f.content)
15091509

15101510
# logout
15111511
f = session.get(self.url_base()+'/?@action=logout')

test/test_templating.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,22 +350,24 @@ def test_number_field(self):
350350
p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
351351
2345678.2345678)
352352
self.assertEqual(p.field(),
353-
('<input name="testnum1@test" size="30" type="text" '
353+
('<input id="testnum1@test" name="testnum1@test" size="30" type="text" '
354354
'value="%s">')%expected_val)
355355
self.assertEqual(p.field(size=10),
356-
('<input name="testnum1@test" size="10" type="text" '
356+
('<input id="testnum1@test" name="testnum1@test" size="10" type="text" '
357357
'value="%s">')%expected_val)
358358
self.assertEqual(p.field(size=10, dataprop="foo", dataprop2=5),
359359
('<input dataprop="foo" dataprop2="5" '
360-
'name="testnum1@test" size="10" type="text" '
360+
'id="testnum1@test" name="testnum1@test" '
361+
'size="10" type="text" '
361362
'value="%s">'%expected_val))
362363

363364
self.assertEqual(p.field(size=10, klass="class1",
364365
**{ "class": "class2 class3",
365366
"data-prop": "foo",
366367
"data-prop2": 5}),
367368
('<input class="class2 class3" data-prop="foo" '
368-
'data-prop2="5" klass="class1" '
369+
'data-prop2="5" id="testnum1@test" '
370+
'klass="class1" '
369371
'name="testnum1@test" size="10" type="text" '
370372
'value="%s">')%expected_val)
371373

@@ -377,8 +379,8 @@ def test_number_field(self):
377379
p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
378380
"2345678.2345678")
379381
self.assertEqual(p.field(),
380-
('<input name="testnum1@test" size="30" type="text" '
381-
'value="2345678.2345678">'))
382+
('<input id="testnum1@test" name="testnum1@test" '
383+
'size="30" type="text" value="2345678.2345678">'))
382384

383385
# test with None value, pretend property.__default_value = Null which
384386
# is the default. It would be returned by get_default_value
@@ -387,8 +389,8 @@ def test_number_field(self):
387389
p = NumberHTMLProperty(self.client, 'testnum', '1', property,
388390
'test', None)
389391
self.assertEqual(p.field(),
390-
('<input name="testnum1@test" size="30" type="text" '
391-
'value="">'))
392+
('<input id="testnum1@test" name="testnum1@test" '
393+
'size="30" type="text" value="">'))
392394

393395
def test_number_plain(self):
394396
import sys
@@ -570,7 +572,7 @@ def test_string_rst(self):
570572

571573
def test_string_field(self):
572574
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with [email protected] embedded &lt; html</b>')
573-
self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string &lt;b&gt; with [email protected] embedded &amp;lt; html&lt;/b&gt;">')
575+
self.assertEqual(p.field(), '<input id="test1@test" name="test1@test" size="30" type="text" value="A string &lt;b&gt; with [email protected] embedded &amp;lt; html&lt;/b&gt;">')
574576

575577
def test_string_multiline(self):
576578
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with [email protected] embedded &lt; html</b>')
@@ -746,7 +748,7 @@ def test_DateHTMLWithText(self):
746748
self.assertIs(type(d._value), str)
747749
self.assertEqual(d.pretty(), "2021-01-01 11:22:10")
748750
self.assertEqual(d.plain(), "2021-01-01 11:22:10")
749-
input = """<input name="test1@test" size="30" type="text" value="2021-01-01 11:22:10"><a class="classhelp" data-calurl="test?@template=calendar&amp;amp;property=test&amp;amp;form=itemSynopsis&amp;date=2021-01-01 11:22:10" data-height="200" data-width="300" href="javascript:help_window('test?@template=calendar&amp;property=test&amp;form=itemSynopsis&date=2021-01-01 11:22:10', 300, 200)">(cal)</a>"""
751+
input = """<input id="test1@test" name="test1@test" size="30" type="text" value="2021-01-01 11:22:10"><a class="classhelp" data-calurl="test?@template=calendar&amp;amp;property=test&amp;amp;form=itemSynopsis&amp;date=2021-01-01 11:22:10" data-height="200" data-width="300" href="javascript:help_window('test?@template=calendar&amp;property=test&amp;form=itemSynopsis&date=2021-01-01 11:22:10', 300, 200)">(cal)</a>"""
750752
self.assertEqual(d.field(), input)
751753

752754
# common markdown test cases

0 commit comments

Comments
 (0)