-
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
knockout component validation #507
Comments
I didn't encounter any issues with components but I don't quite understand what you mean by
I've created a fiddle for this. Can you change it to match you current use case, please? This would make things much clear. Thanks. |
Hi Thank you for the prompt response and the JS Fiddle! I have updated your fiddle with a small example - more similar to what i have. And as in my code the validation does not work. Thanks |
Thanks for the fix. One other issue that i think might be related to this is in the below fiddle. When try access the errors or check for them the below code does not work. var result = ko.validation.group(self,{deep:true});
|
Ok.... Not sure what you mean by use "errors().length" Sorry my point was that even result.isValid() is failing... how would i call this now? |
Here's the updated fiddle http://jsfiddle.net/0xnyt6st/ |
Thanks all working. |
This seems like a good solution to obtain error messages upon the group call. However, unlike stated in the http://jsfiddle.net/0xnyt6st/ comments, the showAllMessages is not available on the result which is a simple array of strings. Is there any way to NOT display the message upon edit (messagesOnModified: false) and display them after the 'test' click? I've updated the fiddle to demonstrate the lack of 'showAllMessages' (http://jsfiddle.net/0xnyt6st/11/). Am I missing something? |
@BredStik I think you're a bit incorrect the way things work. var result = ko.validation.group({ /* some model to validate */ }, { /* options */ });
// Ask for errors
result();
// show all errors
result.showAllMessages();
// check if any message is shown
result.isAnyMessageShown();
// The idea is that some methods which were previously attached
// on the model passed to ko.validation.group are attached to result instead. I hope this clarifies a bit. |
Thanks for the reply. I get it now, got confused over the result function returned value and the result object itself. Thanks for the clarifications! |
Hi
I am currently using knockout components (with require.js).
e.g ko.components.register('appointmentform', { require: 'mod/appointmentForm' });
I want to enable validations within this plugin. If i call component.errors().length i get the correct number of errors, however when calling:
var result = ko.validation.group(self, { deep: true });
result.showAllMessages(true);
Note: self in the above example is the component and not the "viewModel'
No messages are displayed. I can see the
is placed next to all the relevant controls. But there is no message and it is marked as display none.
My init code is as follows:
ko.validation.init({
registerExtenders: true,
messagesOnModified: true,
insertMessages: true,
parseInputAttributes: true,
messageTemplate: null
});
Does knockout validation support components?
The text was updated successfully, but these errors were encountered: