Closed sohara closed 11 years ago
I think the best way to do this is to rename the validate
methods of each validator: _validate
.
When someone wants to write a validator, he has to implement the _validate
method. This method is private.
Then, each Ember.Validator
should have a validate
method that will call its shouldSkipValidations(object, attr, value)
and will call _validate
if the returned value is truthy. This method is firstly implemented in Ember.Validator
. and just return false
by default.
This implementation results in some changes, so if you won't have time for them, I will do it when possible. Of course, if you have any better idea or remark, I'll be glad to read it!
That sounds like a good way to do it. I'll work on it this evening or tomorrow and get you a new pull request.
Hi @lcoq I've add a couple of commits that change the implementation to what you suggested. I also added a note about skipping validations using the allowBlank
option in the readme file. Let me know what you think.
Sean
Also, let me know if you prefer that I rebase these changes into a single commit.
I really like what you did, except for one thing:
I told you the method shouldSkipValidations
just return false
by default.
After reading your code, I believe it should return true
when the allowBlank
is true
by default.
So, except for the PresenceValidator
, no one validator has to override the shouldSkipValidations
. What do you think? Do you agree?
Anyway, thanks a lot for you time
Sure, I think the things you mentioned make sense. I will try to make these changes tomorrow and let you know when it has been updated. Thanks!
I've updated the pull request according to your suggestions. Let me know what you think! Thanks :)
Merged in master. Thanks @sohara !
Awesome, thanks guys! Nice addition to the API.
I don't intend this as a real pull request but I would like to get your feedback early on how best to implement this feature.
On the implementation: I've add a simple conditional on the
validate
method ofEmber.Validators.NumericalityValidator
. I'm not sure if this a too ugly way to do it? If I continue this way I would add this conditional to validate method of the other validators. Perhaps another way would be to implement this somehow in the parentEmber.Validator
class. But this would meed the classes that extendEmber.Validator
would need to all call_super()
and then perhaps you lose the error handling to ensure they all have avalidate
function. Also, it doesn't make sense for the presence validator. Of course I'll modify the documentation for the real pull request.On the test: It's the simplest test, just to ensure blank strings are allow through. But it passes and none of the other tests are failing as a result.
If you have a moment, please let me know your thoughts on the best approach and I'll go back and revise.
Thanks, Sean