bootstrap-validator icon indicating copy to clipboard operation
bootstrap-validator copied to clipboard

fields that are required but disabled are not filtered in isIncomplete()

Open Langmans opened this issue 8 years ago • 2 comments

Disabled input fields are checked for validation...

I have a form with a collapsed area. When i toggle the collapse, I set the disabled property of the inputs in that area to false so they are not validated. But the inputs are also required when they are shown.

https://github.com/1000hz/bootstrap-validator/blob/master/js/validator.js#L303

it should be "[required]:not([disabled])":

Validator.prototype.isIncomplete = function () {
    function fieldIncomplete() {
      var value = getValue($(this))
      return !(typeof value == "string" ? $.trim(value) : value)
    }

    return !!this.$inputs.filter('[required]:not([disabled])').filter(fieldIncomplete).length
  }

Another solution would be to add the condition to update() where it sets this.$inputs

related link: https://api.jquery.com/enabled-selector/ :enabled isn't used because it needs to check the attribute in my opinion.

possibly related to #328, #333

Langmans avatar Jul 05 '17 07:07 Langmans

I would set .attr('data-validate', false) and call .validator('update') instead of setting disabled.

1000hz avatar Jul 10 '17 19:07 1000hz

Yup, thats what i did too. Still, it would make sense to ignore disabled inputs, even if it is the default browser behavior.

Langmans avatar Jul 10 '17 21:07 Langmans