administrate-field-enum
administrate-field-enum copied to clipboard
Add include_blank option to enum field
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.