Skip to content

Conversation

duduribeiro
Copy link

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant