k0lpak
k0lpak

Reputation: 553

KnockoutJS can't set input field to false value

How can I set the value of an <input> to false? true works fine.

Model:

function Model(){
   self = this;
   self.Test = ko.observable(false);
};

HTML:

<input type="text" data-bind="value:Test"/>

Upvotes: 2

Views: 276

Answers (1)

Alnitak
Alnitak

Reputation: 339786

An <input type="text"> expects a text value, and you're supplying a boolean.

The boolean value false is considering "falsey" when passed in the value attribute, which is the same as supplying no value, so it appears blank.

It works for true because you end up with true.toString()

Upvotes: 4

Related Questions