Make a Moode Form element mandatory only when enabled

Make a Moode Form element mandatory only when enabled

by Tri Le -
Number of replies: 0

Are there any standard way to make an element in Moodle form mandatory just when enabled?

I have a select box and a textbox that is enabled or disabled depending on another checkbox. When the user tick the checkbox, they must choose an option in the select box.

However, if I use the addRule(.."required") of Moodle form, they are required even when disabled and prevent the user to submit the form.

My last resort is using javascript to manipulate these things, but I wonder whether there is a standard "Moodle way" to do so.

Average of ratings: -