Skip to content

checked for the input checkbox works wrong with undefined or null variables #2309

@dzavodnikov

Description

@dzavodnikov

I have such code:

<input  type="checkbox" data-bind="value: username, checked: selectedUsers" />

and if selectedUsers is null or undefined I get an error:

Uncaught TypeError: Array.prototype.indexOf called on null or undefined
    at indexOf (<anonymous>)
    at Object.arrayIndexOf (knockout.js:164)
    at updateView (knockout.js:4144)
    at Function.evaluateImmediate_CallReadThenEndDependencyDetection (knockout.js:2183)
    at Function.evaluateImmediate_CallReadWithDependencyDetection (knockout.js:2150)
    at Function.evaluateImmediate (knockout.js:2111)
    at Function.evaluatePossiblyAsync (knockout.js:2076)
    at Function.notifySubscribers (knockout.js:1330)
    at Function.evaluateImmediate_CallReadWithDependencyDetection (knockout.js:2163)
    at Function.evaluateImmediate (knockout.js:2111)

I think that Knockout should check variable first and just leave all checkboxes unselected, but not generate and error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions