fix: improve handling of boolean form fields
This commit is contained in:
parent
2503836ef5
commit
43ad0ae1c1
5 changed files with 27 additions and 3 deletions
|
@ -995,7 +995,16 @@ class Form:
|
|||
model_data = {}
|
||||
|
||||
def assign(field):
|
||||
model_data[field.oid] = make_json_safe(field.cstruct)
|
||||
value = field.cstruct
|
||||
|
||||
# TODO: we need a proper true/false on the Vue side,
|
||||
# but deform/colander want 'true' and 'false' ..so
|
||||
# for now we explicitly translate here, ugh. also
|
||||
# note this does not yet allow for null values.. :(
|
||||
if isinstance(field.typ, colander.Boolean):
|
||||
value = True if field.typ.true_val else False
|
||||
|
||||
model_data[field.oid] = make_json_safe(value)
|
||||
|
||||
for key in self.fields:
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ in the namespace:
|
|||
* :class:`deform:deform.widget.TextAreaWidget`
|
||||
* :class:`deform:deform.widget.PasswordWidget`
|
||||
* :class:`deform:deform.widget.CheckedPasswordWidget`
|
||||
* :class:`deform:deform.widget.CheckboxWidget`
|
||||
* :class:`deform:deform.widget.SelectWidget`
|
||||
* :class:`deform:deform.widget.CheckboxChoiceWidget`
|
||||
* :class:`deform:deform.widget.MoneyInputWidget`
|
||||
|
@ -41,7 +42,7 @@ in the namespace:
|
|||
import colander
|
||||
from deform.widget import (Widget, TextInputWidget, TextAreaWidget,
|
||||
PasswordWidget, CheckedPasswordWidget,
|
||||
SelectWidget, CheckboxChoiceWidget,
|
||||
CheckboxWidget, SelectWidget, CheckboxChoiceWidget,
|
||||
MoneyInputWidget)
|
||||
from webhelpers2.html import HTML
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
v-model="${vmodel}"
|
||||
native-value="true"
|
||||
tal:attributes="attributes|field.widget.attributes|{};">
|
||||
{{ ${vmodel} }}
|
||||
{{ ${vmodel} ? "Yes" : "No" }}
|
||||
</b-checkbox>
|
||||
</div>
|
||||
|
|
4
src/wuttaweb/templates/deform/readonly/checkbox.pt
Normal file
4
src/wuttaweb/templates/deform/readonly/checkbox.pt
Normal file
|
@ -0,0 +1,4 @@
|
|||
<tal:omit tal:define="true_val true_val|field.widget.true_val;">
|
||||
<span tal:condition="cstruct == true_val">Yes</span>
|
||||
<span tal:condition="cstruct != true_val">No</span>
|
||||
</tal:omit>
|
Loading…
Add table
Add a link
Reference in a new issue