MCPcopy
hub / github.com/fabiospampinato/cash / val

Function val

src/forms/val.ts:15–49  ·  view source on GitHub ↗
( this: Cash, value?: string | string[] )

Source from the content-addressed store, hash-verified

13function val ( this: Cash ): string | string[];
14function val ( this: Cash, value: string | string[] ): Cash;
15function 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
51fn.val = val;

Callers

nothing calls this directly

Calls 5

getValueFunction · 0.85
isNullFunction · 0.85
eachFunction · 0.85
isUndefinedFunction · 0.85
eachMethod · 0.65

Tested by

no test coverage detected