-
Notifications
You must be signed in to change notification settings - Fork 39
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
Question: How would you handle observable extensions ? #5
Comments
I have the same issue: How is the new syntax to write this?: result.name = ko.observable(item.name).extend({required: true}); |
You can create an observable on your objects, ko-es5 will turn them into properties just the same.
This code should work. Or you can use
Trying to fit this with ko-validation is more difficult because the validation binding handlers expect to receive the observable itself, not his value. |
Did you ever get it working with knockout validation? I raised a similar sort of question on their board a while back but didnt get an answer: |
@grofit I did, although it's not very pretty. I used a binding preprocessor http://knockoutjs.com/documentation/binding-preprocessing.html A binding preprocessor receives the source text of your binding and you're free to manipulate it anyway that you want. There are several ways you can go with this. What I did is that I wanted explicit opt-in into validation, so I did this: if the binding text ended with a bang I would then use it like so: Note that it's been quite some time since I last looked into that. Maybe there's a better way now. |
So the setup is basically a list of I assume the |
After playing about a bit here is what I came up with:
Works fine, although it seems the |
@grofit That was pretty much my setup, except that I used a helper function to declare validation rules easily. It was used something like this: var vm = { amount: 2, name: 'jods' };
ko.track(vm);
setupValidation(vm, { amount: { min: 3, max: 5 }, name: { required: true } }); For I think you have three options to make those things work:
var vm = {
amount: ko.observable(2).extend({ min: 3, max: 5 })
};
// call `group` and `validatedObservable` if you want to.
// Then:
ko.track(vm); |
Yeah I am currently just making a custom object to check over the isValid stuff. The latter option is not really an option here as I am trying to get away from the ko.observable calls. Thanks for info though. |
We use an extender to force type stored in the underlying value ( value binding in text boxes pushes strings into observable ).
How would I wire this up if I was to use ko.track ?
The text was updated successfully, but these errors were encountered: