-
Notifications
You must be signed in to change notification settings - Fork 379
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
validatedObservable group options #461
Comments
@danda1man I belive using a validation group you can achieve this. See the wiki for an example. |
You can bit since a group is created on the original model, there are a few exceptions that will occur if you have other objects in your view model. My specific case was i was trying to hide error messages after mapping existing data into my model, but nested objects errors were still showing. If i made those nested objects validatedObservables, errors are thrown when calling: viewModel.errors.showAllMessages (false) This was a simple fix with less overhead than creating extra groups |
@danda1man Please provide a fiddle/plunk or some tests for this. Thanks. |
Broken as is: http://plnkr.co/7R97MF7fGVfU1nL1csle Anything deeper than the root level will not get caught in default grouping and so the errors will show. The fix as I mentioned earlier is modifying the validatedObservable constructor to take options so you can pass deep to the grouping. Here is a plunkr of my modification: http://plnkr.co/109BanVzSJ5iCi4Vwer0 |
@danda1man Thanks. This looks good. I'll write some tests for this and submit a pull request, unless you want to do it. |
Go ahead :) |
I don't think anyone is keeping this up anymore, but I found this change helpful when working with nested view models. Without being able to pass the deep option on instantiation, the validation will not give you all the errors or hide all the errors, so I added in the options to the constructor and passed them to the initial group.
ko.validatedObservable = function (initialValue, options) {
if (!kv.utils.isObject(initialValue)) { return ko.observable(initialValue).extend({ validatable: true }); }
The text was updated successfully, but these errors were encountered: