Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include_blank option to enum field #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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