The "uniqueName" binding
Purpose
The uniqueName
binding ensures that the associated DOM element has a nonempty name
attribute. If the DOM element did not have a name
attribute, this binding gives it one and sets it to some unique string value.
You won鈥檛 need to use this often. It鈥檚 only useful in a few rare cases, e.g.:
-
Other technologies may depend on the assumption that certain elements have names, even though names might be irrelevant when you鈥檙e using KO. For example, jQuery Validation currently will only validate elements that have names. To use this with a Knockout UI, it鈥檚 sometimes necessary to apply the
uniqueName
binding to avoid confusing jQuery Validation. See an example of using jQuery Validation with KO. -
IE 6 does not allow radio buttons to be checked if they don鈥檛 have a
name
attribute. Most of the time this is irrelevant because your radio button elements will have name attributes to put them into mutually-exclusive groups. However, just in case you didn鈥檛 add aname
attribute because it鈥檚 unnecessary in your case, KO will internally useuniqueName
on those elements to ensure they can be checked.
Example
<input data-bind="value: someModelProperty, uniqueName: true" />
Parameters
-
Main parameter
Pass
true
(or some value that evaluates as true) to enable theuniqueName
binding, as in the preceding example. -
Additional parameters
- None
Dependencies
None, other than the core Knockout library.