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

Commit 5d74c22

Browse files
committed
no longer skipping a custom validator if its attr has a falsy value. fixes #475
1 parent 3417346 commit 5d74c22

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

js/tests/unit/validator.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ $(function () {
533533
+ '<input type="text" id="bar" data-foo="foo" value="bar">'
534534
+ '<div class="help-block with-errors"></div>'
535535
+ '</div>'
536+
+ '<div class="form-group">'
537+
+ '<input type="text" id="baz" data-foo value="baz">'
538+
+ '<div class="help-block with-errors"></div>'
539+
+ '</div>'
536540
+ '<button type="submit">Submit</button>'
537541
+ '</form>'
538542

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

557562
QUnit.test('should update set of fields', function (assert) {

js/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
$.each(this.validators, $.proxy(function (key, validator) {
205205
var error = null
206206
if ((getValue($el) || $el.attr('required')) &&
207-
($el.attr('data-' + key) || key == 'native') &&
207+
($el.attr('data-' + key) !== undefined || key == 'native') &&
208208
(error = validator.call(this, $el))) {
209209
error = getErrorMessage(key) || error
210210
!~errors.indexOf(error) && errors.push(error)

0 commit comments

Comments
 (0)