Book Image

Getting Started with Knockout.js for .NET Developers

By : Andrey Ankshin
Book Image

Getting Started with Knockout.js for .NET Developers

By: Andrey Ankshin

Overview of this book

Table of Contents (14 chapters)
Getting Started with Knockout.js for .NET Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Form fields bindings


Forms are important parts of many web applications. In this section, we will learn about a number of data bindings to work with the form fields:

  • The value binding

  • The click binding

  • The submit binding

  • The event binding

  • The checked binding

  • The enable binging

  • The disable binding

  • The options binding

  • The selectedOptions binding

The value binding

Very often, forms use the input, select and textarea elements to enter text. Knockout.js allows work with such text via the value binding, as shown in the following example (PersonalPage-Binding-Value.html):

The Model will be as follows:

var person = {
  firstName: "John"
};

The ViewModel will be as follows:

var PersonViewModel = function() {
  var self = this;
  self.firstName = ko.observable(person.firstName);
};

The View will be as follows:

<form>
  The first name is <input type="text" data-bind="value: firstName" />.
</form>

The value property of the text input element binds to the firstName property of the ViewModel.

The click...