Skip to content

Commit 816b527

Browse files
Added fix to not add "required" attr unless field is actually required.
1 parent 6caddcc commit 816b527

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/selectize.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,9 @@ $.extend(Selectize.prototype, {
14391439
var self = this;
14401440
var invalid = self.isRequired && !self.items.length;
14411441
if (!invalid) self.isInvalid = false;
1442-
self.$control_input.prop('required', invalid);
1442+
if (self.isRequired) {
1443+
self.$control_input.prop('required', invalid);
1444+
};
14431445
self.refreshClasses();
14441446
},
14451447

test/setup.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,30 @@
218218
}
219219
});
220220

221+
describe('<select> (not required)', function(){
222+
var $form, $button, test;
223+
224+
beforeEach(function() {
225+
test = setup_test('<select>' +
226+
'<option value="">Select an option...</option>' +
227+
'<option value="a">A</option>' +
228+
'</select>', {});
229+
$form = test.$select.parents('form');
230+
$button = $('<button type="submit">').appendTo($form);
231+
});
232+
afterEach(function() {
233+
$form.off('.test_required');
234+
$button.remove();
235+
});
236+
237+
it('should have isRequired property set to false', function() {
238+
expect(test.selectize.isRequired).to.be.equal(false);
239+
});
240+
it('should not have the required class', function() {
241+
expect(test.selectize.$control.hasClass('required')).to.be.equal(false);
242+
});
243+
});
244+
221245
});
222246

223-
})();
247+
})();

0 commit comments

Comments
 (0)