Clearing the registration form

The final feature of our application is to clear the customer registration form. We will add a button, which the customers can click on to clear any input in the form fields. We will add a corresponding method in the module that will clear all observables in the model.

Let's start by updating the view. Next to the Submit button, add a button to view. Label the button Clear. Bind the click event of the button to a method in the module. We will call this method "clear". Your code for button should look similar to this:

<button type="button" class="btn btn-default" data-bind="click: RegistrationForm.clear">Clear</button>

Now that we have updated the view, we can add the clear method to our module. Open the model and add ...

Get KnockoutJS by Example 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.