3 "../core/stripAndCollapse",
8 ], function( jQuery, stripAndCollapse, support, nodeName ) {
15 val: function( value ) {
16 var hooks, ret, isFunction,
19 if ( !arguments.length ) {
21 hooks = jQuery.valHooks[ elem.type ] ||
22 jQuery.valHooks[ elem.nodeName.toLowerCase() ];
26 ( ret = hooks.get( elem, "value" ) ) !== undefined
33 // Handle most common string cases
34 if ( typeof ret === "string" ) {
35 return ret.replace( rreturn, "" );
38 // Handle cases where value is null/undef or number
39 return ret == null ? "" : ret;
45 isFunction = jQuery.isFunction( value );
47 return this.each( function( i ) {
50 if ( this.nodeType !== 1 ) {
55 val = value.call( this, i, jQuery( this ).val() );
60 // Treat null/undefined as ""; convert numbers to string
64 } else if ( typeof val === "number" ) {
67 } else if ( Array.isArray( val ) ) {
68 val = jQuery.map( val, function( value ) {
69 return value == null ? "" : value + "";
73 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
75 // If set returns undefined, fall back to normal setting
76 if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
86 get: function( elem ) {
88 var val = jQuery.find.attr( elem, "value" );
92 // Support: IE <=10 - 11 only
93 // option.text throws exceptions (#14686, #14858)
94 // Strip and collapse whitespace
95 // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
96 stripAndCollapse( jQuery.text( elem ) );
100 get: function( elem ) {
101 var value, option, i,
102 options = elem.options,
103 index = elem.selectedIndex,
104 one = elem.type === "select-one",
105 values = one ? null : [],
106 max = one ? index + 1 : options.length;
115 // Loop through all the selected options
116 for ( ; i < max; i++ ) {
117 option = options[ i ];
119 // Support: IE <=9 only
120 // IE8-9 doesn't update selected after form reset (#2551)
121 if ( ( option.selected || i === index ) &&
123 // Don't return options that are disabled or in a disabled optgroup
125 ( !option.parentNode.disabled ||
126 !nodeName( option.parentNode, "optgroup" ) ) ) {
128 // Get the specific value for the option
129 value = jQuery( option ).val();
131 // We don't need an array for one selects
136 // Multi-Selects return an array
137 values.push( value );
144 set: function( elem, value ) {
145 var optionSet, option,
146 options = elem.options,
147 values = jQuery.makeArray( value ),
151 option = options[ i ];
153 /* eslint-disable no-cond-assign */
155 if ( option.selected =
156 jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
161 /* eslint-enable no-cond-assign */
164 // Force browsers to behave consistently when non-matching value is set
166 elem.selectedIndex = -1;
174 // Radios and checkboxes getter/setter
175 jQuery.each( [ "radio", "checkbox" ], function() {
176 jQuery.valHooks[ this ] = {
177 set: function( elem, value ) {
178 if ( Array.isArray( value ) ) {
179 return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
183 if ( !support.checkOn ) {
184 jQuery.valHooks[ this ].get = function( elem ) {
185 return elem.getAttribute( "value" ) === null ? "on" : elem.value;