WebHare community

Custom form, change required fields based on form input



In a custom form, can I change the ‘required’ setting of field A when (after rendering) changing the value of field B?


Put something like this in the MACRO NEW() of the form object:

^my_maybe_required_field->requiredcondition := FCMatch(^field_to_check, "IN", [ 1, 2 ]);

Refer to mod::publisher/lib/forms/conditions.whlib for functions for more complex scenarios.


You can also set visibility:

^my_maybe_required_field->visiblecondition := FCMatch(^field_to_check, "IN", [ 1, 2 ]);

This isn’t really after rendering, is it? This is more like updating the initial form condition in HareScript because you can’t easily do that in the XML.

(I’ve done that in some situations too. the XML format should be extended to support embedded conditions, but noone has started on that yet)


Indeed, technically it’s not after rendering, but the end result kinda is (dynamically updating required/visibility state after the form has rendered)