Conditional fields or field-options

Does anyone have a suggestion for conditional fields and/or conditional field-options in easyform?
Example: You select option a for field_1 and the options in field_2 change from [x, y, z] to only [y, z]. The user needs to be able to configure the conditions and options.

I'm aware of the following options:

  1. The masterselect widget (plone.formwidget.masterselect) allows configuring such fields in a python schema. It has no supermodel integration (xml-schema) and UI though which is required to work with easyform.

  2. The depends-pattern in patternslib (Depends — Patterns) allows a nice and clean way to create such forms by hand in html. It has no UI, z3c.form and supermodel/easyform integration though.

  3. Write custom JS to filter out options in field_2 depending on the current value of field_1. This approach is probably the quickest but not configurable by a editor and would need to be rewritten/adapted for every conditional field.

I would go for some custom JS code. Configurable mappings could be accomplished through a controlpanel that either the Site Manager or the Plone provider could make (easily)...quick & d̶i̶r̶t̶y̶ easy

I would do it like this

  1. it is possible to add CSS class in easyform, the same was as it is with all XML schema content types (see link below).

  2. Set ID (or a class) on the 'master' to for example 'trigger1'

  3. Set class on the 'children' you want to be triggered to 'trigger1'

  4. Make a js that finds the id or class of the master and then hides children that does not have this class

NOTE: I have looked, but not found any way to set 'data stuff' in xml ( Setting pat-stuff in xml )

Thanks for the suggestions! In the meantime the client has changed his mind and the requirement is no longer :roll_eyes:
If anyone else is planning to create something reuseable I'm happy to help since I would really like to have such a feature in easyform and dexterity :slight_smile:

1 Like