Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating a knockout.js form?

I am using knockout.js in my ASP.NET MVC project. I figured out how to display a form, serialise a JSON object, and display data with the help of following link: How to use knockout.js with ASP.NET MVC ViewModels?

But I am not able to figure out how to validate the form. What is the best solution to validate the form?

like image 731
Gayatri Avatar asked Jun 25 '12 21:06

Gayatri


1 Answers

I have used he Knockout.Validation plugin ( https://github.com/Knockout-Contrib/Knockout-Validation ) which has worked well. It uses extenders in Knockout so you can extend the model properties to include rules like required, min, max, or pattern matches. You can also create custom rules. I created one for a url, for example. It has some built in rule for things like email, too. All of this is in the github page in the docs. It has everything you need to get started.

Another option is to use jquery validation, which also works well.

like image 138
John Papa Avatar answered Sep 28 '22 06:09

John Papa