Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
no longer skipping a custom validator if its attr has a falsy value. f…
Browse files Browse the repository at this point in the history
…ixes #475
  • Loading branch information
1000hz committed Jan 6, 2017
1 parent 3417346 commit 5d74c22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions js/tests/unit/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ $(function () {
+ '<input type="text" id="bar" data-foo="foo" value="bar">'
+ '<div class="help-block with-errors"></div>'
+ '</div>'
+ '<div class="form-group">'
+ '<input type="text" id="baz" data-foo value="baz">'
+ '<div class="help-block with-errors"></div>'
+ '</div>'
+ '<button type="submit">Submit</button>'
+ '</form>'

Expand All @@ -552,6 +556,7 @@ $(function () {
assert.ok($('#foo').data('bs.validator.errors').length === 0, 'foo input is valid')
assert.ok($('#bar').data('bs.validator.errors').length === 1, 'bar input is invalid')
assert.ok($('#bar').data('bs.validator.errors')[0] === 'not equal to foo', 'bar error is custom error')
assert.ok($('#baz').data('bs.validator.errors').length === 1, 'baz ran validator even though data-foo has no attr value')
})

QUnit.test('should update set of fields', function (assert) {
Expand Down
2 changes: 1 addition & 1 deletion js/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
$.each(this.validators, $.proxy(function (key, validator) {
var error = null
if ((getValue($el) || $el.attr('required')) &&
($el.attr('data-' + key) || key == 'native') &&
($el.attr('data-' + key) !== undefined || key == 'native') &&
(error = validator.call(this, $el))) {
error = getErrorMessage(key) || error
!~errors.indexOf(error) && errors.push(error)
Expand Down

0 comments on commit 5d74c22

Please sign in to comment.