Skip to content

Problems with .isValid() on required checkboxes #598

Description

@krnlde

Hey guys! I experienced some problems when making checkboxes required (for example terms and conditions).

See here for reference: http://jsfiddle.net/v6d5y3or/

Expected behaviour: Form .isValid() should reflect the checkbox value: checkbox.true = form.true and checkbox.false = form.false

Actual behaviour: Form .isValid() is always true: checkbox.true = form.true and checkbox.false = form.true

I'm not really sure why this happens and one would think that required: true works together with the checked binding.

A temporary solution to me is to implement a custom validator to make it work as expected:

ko.observable(false).extend({
  validation: [{
    validator: (value, params) => Boolean(value)
  }]
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions