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

Changing validation rules on the fly #49

Open
altunyurt opened this issue Apr 19, 2012 · 3 comments
Open

Changing validation rules on the fly #49

altunyurt opened this issue Apr 19, 2012 · 3 comments
Labels

Comments

@altunyurt
Copy link

I'm trying to update the validation rules of some fields that depend on the values of others on the fly, with no success. Sample code is at http://jsfiddle.net/2vfaV/3/
"deneme" is the main field and validation of "bagimli" depends on the value of deneme. How can i update the validation rule of bagimli?

@ericmbarnard
Copy link
Member

@altunyurt

I believe this is happening because ko.validation is not over-writing your previously added rule, and instead is adding an additional 'required' rule. Also, the required rule hasn't really been tested with a false setting, as ko.validation is not really designed for changing rules on the fly.

For now you can probably workaround the issue by doing something like this:
http://jsfiddle.net/2vfaV/7/

But, like I said... required isn't really expecting to have a 'false' value.

One other option you have is to do .extend({ validatable: false }); ... that will erase all validation from the observable, and then you can - re-assign validation to it. The only problem here is that you would have to call ko.applyBindings again.

@altunyurt
Copy link
Author

@ericmbarnard thanks for the example. I've tried the validatable after posting the question with no success, yet i wasn't aware of rebinding.

@carlschroedl
Copy link

@altunyurt ,

I've applied some functionality from ValidatedViewModel to your example:

http://jsfiddle.net/carlschroedl/d9Mzv/

Does this behave how you expect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants