File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -1439,7 +1439,9 @@ $.extend(Selectize.prototype, {
1439
1439
var self = this ;
1440
1440
var invalid = self . isRequired && ! self . items . length ;
1441
1441
if ( ! invalid ) self . isInvalid = false ;
1442
- self . $control_input . prop ( 'required' , invalid ) ;
1442
+ if ( self . isRequired ) {
1443
+ self . $control_input . prop ( 'required' , invalid ) ;
1444
+ } ;
1443
1445
self . refreshClasses ( ) ;
1444
1446
} ,
1445
1447
Original file line number Diff line number Diff line change 218
218
}
219
219
} ) ;
220
220
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
+
221
245
} ) ;
222
246
223
- } ) ( ) ;
247
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments