Validating data

Now you can send and receive data, but what happens if the user sets some data that is not allowed on the server? You have no control over user input. It is important that if some values are not allowed, you alert the user to it. To validate Knockout data, there is a library called Knockout Validation (which can be found at https://github.com/Knockout-Contrib/Knockout-Validation) that makes this very easy.

This library extends the observables with some values that allow you to validate the data when it changes. We are now going to update our models to add some kind of validation.

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.