Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const value = typeof initial === 'undefined' ? config.defaultValue : initial;
if (!field) {
return;
}
field.data.config = config;
// @ts-ignore
field.initial = value;
// @ts-ignore
field.value = value;
field.touched = config.validateDefaultValue || false;
// These are needed for form "reset" to work correctly!
/* eslint-disable no-param-reassign */
formState.initialValues = setIn(formState.initialValues!, name, value);
formState.values = setIn(formState.values, name, value);
/* eslint-enable no-param-reassign */
}
if (!fieldData || !fieldData.config) {
return data;
}
// Type cast the value
if (fieldData.config.parse) {
value = this.castValue(value, fieldData.config.parse);
}
// Trim the value
if (typeof value === 'string') {
value = value.trim();
}
return setIn(data, name, value);
}, initialData) as Data;
}
if (!field) {
return;
}
field.data.config = config;
// @ts-ignore
field.initial = value;
// @ts-ignore
field.value = value;
field.touched = config.validateDefaultValue || false;
// These are needed for form "reset" to work correctly!
/* eslint-disable no-param-reassign */
formState.initialValues = setIn(formState.initialValues!, name, value);
formState.values = setIn(formState.values, name, value);
/* eslint-enable no-param-reassign */
}
fields.map(async field => {
if (!field) return;
const { name, data: fieldData } = field;
if (fieldData && fieldData.config && fieldData.config.validator) {
const value = getIn(data, name);
if (typeof value !== 'undefined') {
try {
await fieldData.config.validator(value, data);
} catch (error) {
errors = setIn(errors, name, error.message);
}
}
}
}),
);