Let say I have one field that is required, and it will show / hide based on another field with a value is selected.
How to make it as no required when it is hidden?
Let say I have one field that is required, and it will show / hide based on another field with a value is selected.
How to make it as no required when it is hidden?
I would also be very interested in using this feature in my forms.
So far, I have not been able to do it. My workaround is to mark all fields as optional and send the form to a dispatcher using a custom form action. This then validates the input for different scenarios.
Also, in my situation a particular conditional field has to be displayed if either of two "master" fields contain a specific answer. Here, I had to duplicate the flow by creating two very similar conditional fields - the dispatcher then takes care of either scenario.
i.e.
<field name="include_special_mdb"
type="zope.schema.Tuple"
easyform:depends_on="condition: form.widgets.output_type and form.widgets.brand_path_mdb~='pnz' and not form.widgets.output_type~='plenty'; action:both;"
easyform:serverSide="False"
easyform:THidden="False"
easyform:css_class="col-6">
<required>False</required>
<defaultFactory>pnz.intranet.interfaces.pce_special_categories_default</defaultFactory>
<title>Optional: PNZ Produktgruppen hinzufĂŒgen</title>
<description>SchlieĂe zusĂ€tzliche Produkte ein, die zu einer inaktiven oder anderweitig nicht standardmĂ€Ăigen Produktkategorie gehören</description>
<required>False</required>
<value_type type="zope.schema.Choice">
<vocabulary>pnz.intranet.PCExtendedSpecialCategoryVocabulary</vocabulary>
</value_type>
<form:widget type="plone.app.z3cform.widgets.select.SelectFieldWidget"/>
</field>
<field name="include_special_plenty"
type="zope.schema.Tuple"
easyform:depends_on="condition: form.widgets.output_type~='multi_plenty' and form.widgets.brand_path_plenty~='pnz'; action:both;"
easyform:serverSide="False"
easyform:THidden="False"
easyform:css_class="col-6">
<required>False</required>
<defaultFactory>pnz.intranet.interfaces.pce_special_categories_default</defaultFactory>
<title>Optional: PNZ Produktgruppen hinzufĂŒgen</title>
<description>SchlieĂe zusĂ€tzliche Produkte ein, die zu einer inaktiven oder anderweitig nicht standardmĂ€Ăigen Produktkategorie gehören</description>
<required>False</required>
<value_type type="zope.schema.Choice">
<vocabulary>pnz.intranet.PCExtendedSpecialCategoryVocabulary</vocabulary>
</value_type>
<form:widget type="plone.app.z3cform.widgets.select.SelectFieldWidget"/>
</field>
Also note:
Negation has to be put at end of condition. This will work while other variations will not:
easyform:depends_on="condition: form.widgets.output_type and form.widgets.brand_path_mdb~='pnz' and not form.widgets.output_type~='plenty'; action:both;"
Translations need to have their domain (i.e. the dotted name of our policy or theme package) specified, for example in the model
element. This lets us translate the select options:
i18n:domain="pnz.intranet"
i18n:translate="label_hello_world"
msgid "label_hello_world"
msgstr "Hallo Welt"
msgid "label_hello_world"
msgstr "Hello World"
It sounds like you would have to make that field not required but you would check that it has a value if the first field has a value that requires the second one, and youâd have to do that checking with some JavaScript or when you validate the form after submission.