( this: Cash, value?: string | string[] )
| 13 | function val ( this: Cash ): string | string[]; |
| 14 | function val ( this: Cash, value: string | string[] ): Cash; |
| 15 | function val ( this: Cash, value?: string | string[] ) { |
| 16 | |
| 17 | if ( !arguments.length ) return this[0] && getValue ( this[0] ); |
| 18 | |
| 19 | return this.each ( ( i, ele ) => { |
| 20 | |
| 21 | const isSelect = ele.multiple && ele.options; |
| 22 | |
| 23 | if ( isSelect || checkableRe.test ( ele.type ) ) { |
| 24 | |
| 25 | const eleValue = isArray ( value ) ? map.call ( value, String ) : ( isNull ( value ) ? [] : [String ( value )] ); |
| 26 | |
| 27 | if ( isSelect ) { |
| 28 | |
| 29 | each ( ele.options, ( i, option ) => { |
| 30 | |
| 31 | option.selected = eleValue.indexOf ( option.value ) >= 0; |
| 32 | |
| 33 | }, true ); |
| 34 | |
| 35 | } else { |
| 36 | |
| 37 | ele.checked = eleValue.indexOf ( ele.value ) >= 0; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | } else { |
| 42 | |
| 43 | ele.value = isUndefined ( value ) || isNull ( value ) ? '' : value; |
| 44 | |
| 45 | } |
| 46 | |
| 47 | }); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | fn.val = val; |
nothing calls this directly
no test coverage detected