Skip to content

Commit

Permalink
Merge pull request #15 from tdesvenain/master
Browse files Browse the repository at this point in the history
Added a consistent id on single and multiple checkbox widget.
  • Loading branch information
mgedmin committed Feb 19, 2014
2 parents faa2d16 + 9dff698 commit 8e1fbb6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
3 changes: 1 addition & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ CHANGES
3.1.1 (unreleased)
------------------

- Nothing changed yet.

- Added a consistent id on single checkbox and multi checkbox widgets.

3.1.0 (2013-12-02)
------------------
Expand Down
6 changes: 4 additions & 2 deletions src/z3c/form/browser/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ For the boolean, the checkbox widget can be used as well:
>>> widget.update()

>>> print(widget.render())
<span class="option">
<span id="foo">
<span class="option">
<input type="checkbox" id="foo-0" name="bar:list"
class="checkbox-widget required bool-field" value="true"
checked="checked" />
Expand All @@ -215,6 +216,7 @@ For the boolean, the checkbox widget can be used as well:
<label for="foo-1">
<span class="label">no</span>
</label>
</span>
</span>
<input name="bar-empty-marker" type="hidden" value="1" />

Expand Down Expand Up @@ -246,7 +248,7 @@ We can also have a single checkbox button for the boolean.
>>> widget.update()

>>> print(widget.render())
<span class="option">
<span class="option" id="foo">
<input type="checkbox" id="foo-0" name="bar:list"
class="single-checkbox-widget required bool-field"
value="selected" checked="checked" />
Expand Down
18 changes: 12 additions & 6 deletions src/z3c/form/browser/checkbox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Now let's try if we get widget values:

>>> widget.update()
>>> print(widget.render())
<span class="option">
<span id="widget-id">
<span class="option">
<input type="checkbox" id="widget-id-0" name="widget.name:list"
class="checkbox-widget" value="true" />
<label for="widget-id-0">
Expand All @@ -85,6 +86,7 @@ Now let's try if we get widget values:
<label for="widget-id-1">
<span class="label">no</span>
</label>
</span>
</span>
<input name="widget.name-empty-marker" type="hidden" value="1" />

Expand All @@ -94,7 +96,8 @@ field get rendered with a checked flag:
>>> widget.value = 'true'
>>> widget.update()
>>> print(widget.render())
<span class="option">
<span id="widget-id">
<span class="option">
<input type="checkbox" id="widget-id-0" name="widget.name:list"
class="checkbox-widget" value="true"
checked="checked" />
Expand All @@ -107,6 +110,7 @@ field get rendered with a checked flag:
<label for="widget-id-1">
<span class="label">no</span>
</label>
</span>
</span>
<input name="widget.name-empty-marker" type="hidden" value="1" />

Expand Down Expand Up @@ -186,7 +190,7 @@ For there to be a sensible output, we need to give the widget a label:

>>> widget.update()
>>> print(widget.render())
<span class="option">
<span class="option" id="widget-id">
<input type="checkbox" id="widget-id-0"
name="widget.name:list"
class="single-checkbox-widget" value="selected" />
Expand All @@ -206,7 +210,7 @@ will make the box checked:

>>> widget.update()
>>> print(widget.render())
<span class="option">
<span class="option" id="widget-id">
<input type="checkbox" id="widget-id-0"
name="widget.name:list"
class="single-checkbox-widget" value="selected"
Expand All @@ -228,7 +232,7 @@ field
>>> widget.field = Bool(title=u"Do you REALLY want that?")
>>> widget.update()
>>> print(widget.render())
<span class="option">
<span class="option" id="widget-id">
<input type="checkbox" id="widget-id-0"
name="widget.name:list"
class="single-checkbox-widget" value="selected" />
Expand Down Expand Up @@ -294,7 +298,8 @@ Check if a term which __str__ returns non ascii string does not crash the update
>>> print(widget.render())
<html>
<body>
<span class="option">
<span id="widget-id">
<span class="option">
<input class="checkbox-widget" id="widget-id-0" name="widget.name:list" type="checkbox" value="one">
<label for="widget-id-0">
<span class="label">One</span>
Expand All @@ -305,6 +310,7 @@ Check if a term which __str__ returns non ascii string does not crash the update
<label for="widget-id-1">
<span class="label">Two</span>
</label>
</span>
</span>
<input name="widget.name-empty-marker" type="hidden" value="1">
</body>
Expand Down
13 changes: 10 additions & 3 deletions src/z3c/form/browser/checkbox_input.pt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
tal:omit-tag="">
<span class="option"
tal:repeat="item view/items">
tal:omit-tag=""
tal:define="items view/items;
single_checkbox python:len(items) == 1">
<span tal:attributes="id view/id"
tal:omit-tag="single_checkbox"
tal:condition="python:len(items) > 0">
<span class="option"
tal:repeat="item items"
tal:attributes="id python:single_checkbox and view.id or None">
<input type="checkbox" id="" name="" class="" alt="" title=""
tabindex="" disabled="" readonly="" accesskey="" value=""
checked="checked"
Expand Down Expand Up @@ -67,6 +73,7 @@
tal:attributes="for item/id">
<span class="label" tal:content="item/label">Label</span>
</label>
</span>
</span>
<input name="field-empty-marker" type="hidden" value="1"
tal:attributes="name string:${view/name}-empty-marker" />
Expand Down

0 comments on commit 8e1fbb6

Please sign in to comment.