This forum has moved to a new location and is in read-only mode. Please visit to access the new location.


How do you show a backend form field based on a boolean condition?


You might need a bit if Jquery to listen for an onChange event, then show/hide the relevant fields. There could be a simpler way, I'd be interested to know also if there is :)


Hi, in a plugin, there are three ways to do it quite easily :

First solution

Put a disabled condition in the models/your_object_model/fields.yml configuration file of your object's model, like :

# in models/your_object_model/fields.yml
     label: Name of the field to test
     type: (type of your field)
     disabled: true

Second solution

In your model, create a function :

// in models/your_object_model
public function filterFields($fields, $context = null){
if ( *your condition* ) {
          $fields->your_field_name->hidden = true; // to hide the field (example 1)
          $fields->your_field_name->disabled = true; // or just to disable the field (example 2)

Be careful : this solution won't work with dates if there's a datepicker, because in that case the field is not a standard field : it's a widget, and it doesn't follow the same rules...

Third solution

Put a trigger on a field in the models/your_object_model/fields.yml configuration file of your object, for example :

# in models/your_object_model/fields.yml
     label: Name of the field which behaviour you want to change
     type: textarea #(or any other type for your field)
     hidden: true
                action: show # (or other action)
                field: leader_field_control
                condition: checked # (or other condition)
     label: Activate the other Field ?
     type: switch # (or other type for this field)

Thanks to all for your feedbacks !! ;)

Last updated


Based on the 'third solution' can this be used with radio buttons? as well as checkboxes

1-5 of 5

You cannot edit posts or make replies: the forum has moved to