administrate-field-enum icon indicating copy to clipboard operation
administrate-field-enum copied to clipboard

Add include_blank option to enum field

Open duduribeiro opened this issue 2 years ago • 0 comments

Currently the field only renders the blank option if there is no presence validator on the specific field. But there is a problem with this approach because you can have the validator field but with some condition like: validates :matrimonial_regime, presence: true, if: :married? and the field was being rendered without the blank option.

This commit adds a new include_blank that can be set into enum field to force a blank field to be present.

My second thought was to do something like:

([:if, :unless] & f.object.class.validators_on(field.attribute.to_s).find { |v| v.class ==(ActiveRecord::Validations::PresenceValidator }.options.keys).present?

but I thought that include_blank was a better option for persons that wants to add the blank option event if its being validated.

duduribeiro avatar Aug 18 '23 14:08 duduribeiro