What I did:
I had a field which uses a z3c.form SingleCheckboxWidget. Field definition:
some_bool = zope.schema.Bool(
title="some title",
required=False,
default=False,
)
And this was the manually set HTML code for the checkbox:
<input name="some_bool" type="checkbox" />
What I expect to happen:
Saving the form with a checked checkbox should have resulted in a set boolean for the object.
What actually happened:
The boolean was not set because:
-
The default checked value for a input field without a value attribute is on. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
-
The extract method of the SequenceWidget did return the default value, because the lookup for self.terms.getTermsByToken(term) failed with term being on:
|
self.terms.getTermByToken(token) |
-
The terms for the SingleCheckboxWidget are set here:
|
vocabulary.SimpleTerm('selected', 'selected', |
-
Using the following input with a value set to "selected" did solve the issue:
<input name="some_bool" type="checkbox" value="selected" />
I'd have expected that a <input name="some_bool" type="checkbox"/> as a prototypical representation of booleans in html forms to just work out of the box.
I suggest to also add the term on to
|
vocabulary.SimpleTerm('selected', 'selected', |
Not sure, but I guess that would solve the issue...
What version of Python and Zope/Addons I am using:
- Ubuntu 20.04.1
- Python 3.8.5
- z3c.form-3.7.1-py3.8.egg
- Zope-4.5.5-py3.8.egg
- Products.CMFPlone-5.2.4-py3.8.egg
What I did:
I had a field which uses a z3c.form
SingleCheckboxWidget. Field definition:And this was the manually set HTML code for the checkbox:
What I expect to happen:
Saving the form with a checked checkbox should have resulted in a set boolean for the object.
What actually happened:
The boolean was not set because:
The default checked value for a input field without a
valueattribute ison. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#valueThe
extractmethod of theSequenceWidgetdid return the default value, because the lookup forself.terms.getTermsByToken(term)failed withtermbeingon:z3c.form/src/z3c/form/widget.py
Line 255 in 440eb18
The terms for the
SingleCheckboxWidgetare set here:z3c.form/src/z3c/form/browser/checkbox.py
Line 90 in 440eb18
Using the following input with a value set to "selected" did solve the issue:
I'd have expected that a
<input name="some_bool" type="checkbox"/>as a prototypical representation of booleans in html forms to just work out of the box.I suggest to also add the term
ontoz3c.form/src/z3c/form/browser/checkbox.py
Line 90 in 440eb18
Not sure, but I guess that would solve the issue...
What version of Python and Zope/Addons I am using: