Extending the product model

To validate our models using the Knockout Validation library, we are going to extend our model's attributes. Extenders are a basic feature of Knockout. Using extenders we can add some properties to our observables to increase their behavior. For more information on extenders, please refer to the following link:

http://knockoutjs.com/documentation/extenders.html

We are going to extend our product model with some properties that will allow us to validate data by following these steps:

  1. Go to the models/Product.js file.
  2. Update the name field. It should have at least three letters and should contain just letters, numbers, and dashes:
    _name = ko.observable(name).extend({ required: true, minLength: 3, pattern: { message: 'Hey ...

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.