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

Enhancement: Reset option/Skip validation #32

Open
santoshgiridhar opened this issue Jun 7, 2016 · 3 comments
Open

Enhancement: Reset option/Skip validation #32

santoshgiridhar opened this issue Jun 7, 2016 · 3 comments

Comments

@santoshgiridhar
Copy link

Is it possible to skip the validation on click of reset button or restore default values?
While using can.map.validate

doReset: function () {
                    this.attr('myVal','');
                    this.attr('myNum','');
                }
@Macrofig
Copy link
Contributor

Ohhh that's a good use case. Can't believe I haven't seen that one yet. So I like to write these out in the Gherkin syntax, feel free to correct me if I'm wrong...

Given a property has validate options
when the property's value is valid
when the property is "reset"
I expect validation to return no errors.

Given a property has validate options
when the property's value is invalid
when the property is "reset"
I expect the errors for the property to be cleared.

@Macrofig
Copy link
Contributor

Macrofig commented Jun 13, 2016

One possible solution, and the one I'm leaning towards, is having a preFlight method that runs a callback. In the callback, you can do any checks you need to do and return a boolean. If false, can-validate will not run any validate calls and just allows the setter to do its thing. If true then we continue to validate the new value.

Thoughts?

@santoshgiridhar
Copy link
Author

preFlight method sounds good.
A Boolean value to run validate on demand makes more sense.

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

No branches or pull requests

2 participants