File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,13 @@ var getAttr = function(elem, name) {
44
44
if ( elem . name === 'option' && name === 'value' ) {
45
45
return $ . text ( elem . children ) ;
46
46
}
47
+
48
+ // Mimic DOM with default value for radios/checkboxes
49
+ if ( elem . name === 'input' &&
50
+ ( elem . attribs . type === 'radio' || elem . attribs . type === 'checkbox' ) &&
51
+ name === 'value' ) {
52
+ return 'on' ;
53
+ }
47
54
} ;
48
55
49
56
var setAttr = function ( el , name , value ) {
Original file line number Diff line number Diff line change @@ -399,10 +399,18 @@ describe('$(...)', function() {
399
399
var val = $ ( 'input[name="checkbox_off"]' ) . val ( ) ;
400
400
expect ( val ) . to . equal ( 'off' ) ;
401
401
} ) ;
402
+ it ( '.val(): on valueless checkbox should get value' , function ( ) {
403
+ var val = $ ( 'input[name="checkbox_valueless"]' ) . val ( ) ;
404
+ expect ( val ) . to . equal ( 'on' ) ;
405
+ } ) ;
402
406
it ( '.val(): on radio should get value' , function ( ) {
403
407
var val = $ ( 'input[type="radio"]' ) . val ( ) ;
404
408
expect ( val ) . to . equal ( 'off' ) ;
405
409
} ) ;
410
+ it ( '.val(): on valueless radio should get value' , function ( ) {
411
+ var val = $ ( 'input[name="radio_valueless"]' ) . val ( ) ;
412
+ expect ( val ) . to . equal ( 'on' ) ;
413
+ } ) ;
406
414
it ( '.val(): on multiple select should get an array of values' , function ( ) {
407
415
var val = $ ( 'select#multi' ) . val ( ) ;
408
416
expect ( val ) . to . eql ( [ '2' , '3' ] ) ;
Original file line number Diff line number Diff line change @@ -46,8 +46,10 @@ exports.inputs = [
46
46
'<select id="one-nested"><option>Option not selected</option><option selected>Option <span>selected</span></option></select>' ,
47
47
'<input type="text" value="input_text" />' ,
48
48
'<input type="checkbox" name="checkbox_off" value="off" /><input type="checkbox" name="checkbox_on" value="on" checked />' ,
49
+ '<input type="checkbox" name="checkbox_valueless" />' ,
49
50
'<input type="radio" value="off" name="radio" /><input type="radio" name="radio" value="on" checked />' ,
50
51
'<input type="radio" value="off" name="radio[brackets]" /><input type="radio" name="radio[brackets]" value="on" checked />' ,
52
+ '<input type="radio" name="radio_valueless" />' ,
51
53
'<select id="multi" multiple><option value="1">1</option><option value="2" selected>2</option><option value="3" selected>3</option><option value="4">4</option></select>' ,
52
54
'<select id="multi-valueless" multiple><option>1</option><option selected>2</option><option selected>3</option><option>4</option></select>'
53
55
] . join ( '' ) ;
You can’t perform that action at this time.
0 commit comments