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

RegisterExtenders invoked before Init, cannot avoid adding rules to ko.extends. #404

Open
slaneyrw opened this issue Feb 7, 2014 · 6 comments
Labels

Comments

@slaneyrw
Copy link

slaneyrw commented Feb 7, 2014

There is an option to set registerExtenders to false when init is invoked to bypass registerExtenders, but the bootstrap has already executed kv.registerExtenders ( ~ line 914 )

//now register all of these!
(function () {
    kv.registerExtenders();
}());

You cannot avoid registering all the rules as ko.extensions

@crissdev
Copy link
Member

@slaneyrw Indeed, you cannot prevent the rules from being registered during init, but why would you need this? You can change / remove / replace the builtin rules quite easily. Can you provide a use case for this? Thanks.

@slaneyrw
Copy link
Author

To avoid a clash of registered extenders.

@crissdev
Copy link
Member

I would recommend choosing unique names for your custom rules. But the problem I currently see is that although we have a registerExtenders option it cannot be used. I will look into this more and see if either I'm wrong or it can be fixed.

@crissdev crissdev added the todo label Nov 26, 2014
@slaneyrw
Copy link
Author

It's not only custom rules, but you are also competing with all other knockout extenders. for example, I had a number extension that forces all values into an observable to be converted into a number ( as knockout will push in a text value if bound to an input ). The number extender from the validation library overwrote mine forcing me to rename my custom extender.

@crissdev
Copy link
Member

@slaneyrw Sorry for the delay on this one.

Until some sort of solution is found for this you may choose to code an unregister method like the following:

function unregisterExtenders() {
    for (var ruleName in ko.validation.rules) {
        if (ko.validation.rules.hasOwnProperty(ruleName)) {
            if (ko.extenders[ruleName]) {
                delete ko.extenders[ruleName];
            }
        }
    }
}

This method will leave the other extenders like validation and validatable intact, so you can use your own custom rules with no problems.

@crissdev
Copy link
Member

@slaneyrw Some work is done in this direction and it would be great to have some feedback on it. See branch issue-545 and related issue #545. Thanks.

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

2 participants