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

Validation Messages showing on Initial Load #241

Closed
jatindua81 opened this issue Mar 5, 2013 · 8 comments
Closed

Validation Messages showing on Initial Load #241

jatindua81 opened this issue Mar 5, 2013 · 8 comments

Comments

@jatindua81
Copy link

Hi There

We are currently working on a razor application using knockout 2.1. We have started using the knockout validation library.

The issue is that we have a view with an Add button. Clicking the Add button results in a popup with a couple of Select and date picker controls. Problem is that the ko validations are being fired on the initial load of the popup. What are we missing here - maybe on the initial load of the view, knockout thinks the view model has changed and therefore fires the validations? How can we determine which property on the view model has changed and is there a way to stop that explicitly?

We are trying "this.<>.isModified(false)" but no luck. This isnt working too:
ko.validation.configure({
registerExtenders: true,
messagesOnModified: true,
insertMessages: false,
parseInputAttributes: true,
messageTemplate: null,
grouping: {
deep: true
}
});

Any help will be appreciated guys

Thanks

Jatin

@stevegreatrex
Copy link
Contributor

You should be able to manually set isModified(false) - can you create a jsFiddle demonstrating the problem?

@jatindua81
Copy link
Author

Hi Steve, Thanks for replying. We are manually setting isModified(false) as mentioned above. Will setup a jsFiddle and post the link to it here...

@jatindua81
Copy link
Author

Hi Steve,

Here is a JsFiddle of what I am trying to achieve - http://jsfiddle.net/h3Efe/7/

The Add button should popup the "EditLeaveForm" div as a modal with the Hour property required. As soon as the popup loads, the knockout validations is firing - even though I set this.hours.isModified(false); in the add function

Help will be greatly appreciated

thanks

@jatindua81
Copy link
Author

Sorry Steve - the previous fiddle isn't working. Have simplified it - http://jsfiddle.net/3Lqsx/1307/

As you can see "Hours Required" comes up on load

thanks

@stevegreatrex
Copy link
Contributor

I believe the problem is that you are directly binding to the errors collection instead of using the validationMessage binding. messagesOnModified only affects messages generated by validationMessage so the isModified flag will have no effect.

You could try creating a computed allModified flag on your view model and only display the errors when that is true: http://jsfiddle.net/stevegreatrex/3Lqsx/1318/

@jatindua81
Copy link
Author

Thats helpful. thanks Steve! I assume there is no validation summary support in the knockout validation library and this is the way its usually done?

thanks

@delixfe
Copy link
Contributor

delixfe commented Mar 25, 2013

@jatindua81 I have created the pull request #226 which gives you a summary support.

@crissdev
Copy link
Member

Closing this issue since Steve provided all the necessary details and example.
Updated Steve's fiddle http://jsfiddle.net/hasn57hr/

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

4 participants