lcoq / ember-validations

Ember-Validations - An Ember.js library for handling object validations
MIT License
122 stars 25 forks source link

Should numericality validator require presence of property? #9

Closed sohara closed 11 years ago

sohara commented 12 years ago

Hi there, I've run into an issue where I'd like to validator to ensure the numericality of a property only if it is present? Right now the validator is invalidating the model if e.g. a blank string (as in filling a form) is assigned to property. Shouldn't the numericality validator first ensure the property is not blank and only then add the 'notNumber' error message for that property?

If you agree, I can submit a pull request, but I thought I'd ask first. Thanks, Sean

sohara commented 12 years ago

To be more specific, I'm wondering if it might be desirable to emulate the behaviour of the rails numericality validator with its :allow_nil option.

lcoq commented 11 years ago

I totally agree. Validators should have a allowBlank option, so validations will be skipped when the value is blank (e.g. null, undefined or blank string). I don't see any reason to add a allowNil option, as properties that are binded in a form will all be strings. What do you think about that ? Anyway, I would be pleased to consider a pull request.

yossi-shasho commented 11 years ago

I think all validators except presence should allow null. Its the only way to support all use cases. Currently, its impossible to support objects with optional numeric values.

lcoq commented 11 years ago

@yossi-shasho Definitely. There is a pull request about this feature. Consequently, I close this issue in favor of #11.