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

Opt-out option for makeBindingHandlerValidatable #477

Open
jods4 opened this issue Dec 7, 2014 · 5 comments
Open

Opt-out option for makeBindingHandlerValidatable #477

jods4 opened this issue Dec 7, 2014 · 5 comments

Comments

@jods4
Copy link

jods4 commented Dec 7, 2014

I would love if there was an option to opt-out of the 'hacking' of regular bindings with validation binding handlers. All it takes is put lines 46-51 of bindingHandlers.js inside a if.

My use case is that I use this validation library with property getters/setters (i.e. ko-es5) and because of this makeBindingHandlerValidatable does not work for me anyway (because it does not receive the observable object, only its value).

BTW, while I was reading this piece of code I noticed that ko.bindingHandlers.validationCore is executed in many bindings but is not the most efficient.

Why not wrap all the code inside a if (ko.validation.utils.isValidatable(observable))? If it's not true this function is a no-op. But currently it would still read the config for the element, check 3 different config settings and check the above condition 3 times :( As a side-effect it would also reduce code size.

@crissdev
Copy link
Member

I see more control over default options, extenders registration is required and is something which will be addressed in the future.

@crissdev
Copy link
Member

@jods4 Can you provide a fiddle as a starting point?

@jods4
Copy link
Author

jods4 commented Feb 11, 2015

Those are simple changes. When I have a bit of time I'll try to create a PR.

@crissdev
Copy link
Member

I was actually referring to a fiddle using ko-es5 and knockout-validation. Creating a PR at this stage it's not recommended because this is something which might be/is related to initialization. Once there will be an issue created (by me, similar to #542) for this, a PR will be very welcome. Thanks anyway.

@jods4
Copy link
Author

jods4 commented Feb 14, 2015

Using ko-es5 together with knockout-validation is worthy more than a quick fiddle I'm afraid.
There are several parts here:

1st setting up the validation rules. Could be done by creating the ko.observable() before calling ko.track() or using ko-es5 ko.getObservable() after the fact. We created a helper method than can take an object describing all the rules for a complete object and applies them at once to a "tracked" ko-es5 entity.

2nd creating the isValid observable at top object level. Pretty much done the same way as (1) with a helper utility method to the rescue.

3rd setting up the validation bindings. To avoid setting them up manually we created a KO binding pre-processor. It turns value: name into the moral equivalent of value: name; validationElement: ko.getObservable('name').

There's more to it but I guess you get the key ideas.

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