MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / FormField

Function FormField

pkg/webui/components/form/field/index.js:74–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72 names.length > 1 ? setValues(values => merge({}, values, value)) : setFieldValue(name, value)
73
74const FormField = props => {
75 const {
76 className,
77 component: Component,
78 decode,
79 description,
80 descriptionValues,
81 disabled: inputDisabled,
82 encode,
83 fieldWidth,
84 name,
85 readOnly,
86 required,
87 title,
88 titleChildren,
89 tooltip,
90 tooltipId,
91 warning,
92 validate,
93 valueSetter,
94 onChange,
95 onBlur,
96 showTitle,
97 } = props
98
99 const {
100 disabled: formDisabled,
101 validateOnBlur,
102 setFieldValue,
103 setFieldTouched,
104 setValues,
105 values,
106 errors: formErrors,
107 registerField,
108 unregisterField,
109 touched: formTouched,
110 } = useFormContext()
111
112 // Generate streamlined `names` variable to handle both composite and simple fields.
113 const names = useMemo(() => name.split(','), [name])
114 const isCompositeField = names.length > 1
115
116 // Extract field state.
117 const errors = compact(at(formErrors, names))
118 const touched = at(formTouched, names).some(Boolean)
119 const encodedValue = useMemo(
120 () => (isCompositeField ? pick(values, names) : get(values, name)),
121 [isCompositeField, name, names, values],
122 )
123
124 // Register field(s) in formiks internal field registry.
125 useEffect(() => {
126 for (const name of names) {
127 registerField(name, { validate })
128 }
129 return () => {
130 for (const name of names) {
131 unregisterField(name)

Callers

nothing calls this directly

Calls 4

extractValueFunction · 0.85
isValueEmptyFunction · 0.85
getFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected