You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The extract method of the SequenceWidget did return the default value, because the lookup for self.terms.getTermsByToken(term) failed with term being on:
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.
This likely will not work:
As the docstring for `SequenceWidget` tells us its purpose is to
support the use case "possible input values specified via a sequence
of values".
You suggest to use a two element sequence as values for a
`SingleCheckboxWidget` but such a widget supports only a single value.
You might avoid HTML problems by the wrong `SequenceWidget` use
through your manually created HTML but you must keep in mind
that there will be a value extractor which translates the widget
value into the field value and it likely does not know how to
handle a new value "on".
The `z3c.form` framework is quite complex being composed of
a set of **cooperating** components, among them
"field", "widget", "input template", "value extractor".
Each of them makes assumptions about the cooperating partners.
Therefore, it is best for customization purposes to start
with the default component and adapt it as necessary
instead of developing a component from ground zero.
When you look at `checkbox_input.pt` (the input template component
for a checkbox), you will see that the widget instance is supposed
to provide the value to be used in the HTML
(this way, the same widget can be used for checkboxes as well
as for radio buttons). I suggest that your customized template does
the same.
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
value
attribute ison
. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#valueThe
extract
method of theSequenceWidget
did return the default value, because the lookup forself.terms.getTermsByToken(term)
failed withterm
beingon
:z3c.form/src/z3c/form/widget.py
Line 255 in 440eb18
The terms for the
SingleCheckboxWidget
are 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
on
toz3c.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:
The text was updated successfully, but these errors were encountered: