-
Notifications
You must be signed in to change notification settings - Fork 397
Validation should allow empty field value if use allow_nil: true #737
Description
I use the following validation in my Rails model:
validates :website, length: {maximum: 200},
format: {with: URI::regexp},
allow_nil: true
Unfortunately it does not allow me to save empty field value, I'm getting the following error when submit a form:

Looks like it comes from here
https://github.com/DavyJonesLocker/client_side_validations/blob/master/coffeescript/rails.validations.coffee#L287
From my understanding we may need to add return if options.allow_nil == true as well there
And also replace the line
hash[:allow_blank] = true if options[:allow_blank]
with
hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
So you already have it for 'numeric' validation here https://github.com/DavyJonesLocker/client_side_validations/blob/master/lib/client_side_validations/active_model/numericality.rb#L44
so I propose to do the same for 'length' validation
Do you have any issues with the suggestion?
I use Rails 4.2 and 4.2.12 version of this gem but it looks like the issue is persist on master as well