KnockoutJS Declarative Enable Binding - KnockoutJS

What is KnockoutJS Declarative Enable Binding?

KnockoutJS Declarative Enable Binding is generally used to enable certain DOM element based on specified condition. This is useful with form elements like input, select, and textarea.

Syntax

Parameters

  • Parameter consists of Boolean like value which decides whether element should be enabled or not. Element is enabled if parameter is true or true like value.
  • Non Boolean values are considered as loosely Boolean values. Meaning 0 and null are considered as false-like value and Integer and non null objects are considered as true-like value.
  • If the condition in parameter contains any observable value then condition is re-evaluated whenever observable value changes. Correspondingly related markup will be enabled based on condition result.

Example

Let us see below example which explains the use of enable binding:

Output

  • First, Let's carry out the following steps to see how the above code works:
  • Next,Save the above code in enable-bind.htm file.
  • Open this HTML file in a browser.
  • The save button is enabled only when user has typed feedback.

KnockoutJS Declarative Enable Binding

Using random expressions to implement enable binding

We can also use a random expression to decide whether element should be enabled or not.

Example

Let us see below example which demonstrates use of random expression to invoke enable binding:

Output

  • First, Let's carry out the below steps to see how the above code works:
  • Next, Save the above code in enable-random-bind.htm file.
  • Open this HTML file in a browser.
  • The Product Details button is enabled only when product stock is available.

.KnockoutJS Declarative Enable Binding

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

KnockoutJS Topics