Skip to content

Commit

Permalink
Added fix to not add "required" attr unless field is actually required.
Browse files Browse the repository at this point in the history
  • Loading branch information
traviskroberts committed May 12, 2014
1 parent 6caddcc commit 816b527
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,9 @@ $.extend(Selectize.prototype, {
var self = this;
var invalid = self.isRequired && !self.items.length;
if (!invalid) self.isInvalid = false;
self.$control_input.prop('required', invalid);
if (self.isRequired) {
self.$control_input.prop('required', invalid);
};
self.refreshClasses();
},

Expand Down
26 changes: 25 additions & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@
}
});

describe('<select> (not required)', function(){
var $form, $button, test;

beforeEach(function() {
test = setup_test('<select>' +
'<option value="">Select an option...</option>' +
'<option value="a">A</option>' +
'</select>', {});
$form = test.$select.parents('form');
$button = $('<button type="submit">').appendTo($form);
});
afterEach(function() {
$form.off('.test_required');
$button.remove();
});

it('should have isRequired property set to false', function() {
expect(test.selectize.isRequired).to.be.equal(false);
});
it('should not have the required class', function() {
expect(test.selectize.$control.hasClass('required')).to.be.equal(false);
});
});

});

})();
})();

0 comments on commit 816b527

Please sign in to comment.