on master help sign in
fix: avoid undefined value for dynamically added inputs
commit4972cada5fc1e4d74ea950ac1c20b8dcc7ac298c authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 25 Jun 2019, 11:18 (7 years ago) parent18759a2
1 file changed+7−1
src/indigo-react/lib/useForm.js+7−1
src/indigo-react/lib/useForm.js+7−1
@@ -34,6 +34,12 @@ export default function useForm(configs = []) {
3434 (name, value) => _setValues(values => ({ ...values, [name]: value })),
3535 [_setValues]
3636 );
37+ // ^ NB(shrugs): because we're not syncing the initialValue of _additional_
38+ // configs that are added, we won't be able to set an initialValue for a
39+ // dynamic form that then triggers validation. for initial configs,
40+ // initialValue can be a validated string and everything will be happy,
41+ // but for dynamically added input configs, we won't get validation, etc
42+ // until there's a traditional state update.
3743
3844 // track focused states
3945 const [focused, _setFocused] = useState(() =>
@@ -139,7 +145,7 @@ export default function useForm(configs = []) {
139145 autoFocus: config.autoFocus && !config.disabled,
140146 // dom properties below:
141147 bind: {
142− value: values[config.name],
148+ value: values[config.name] || config.initialValue,
143149 onChange: onChange(config.name),
144150 onFocus: onFocus(config.name),
145151 onBlur: onBlur(config.name),