@modular-forms/react
Version:
The modular and type-safe form library for React
16 lines (15 loc) • 653 B
JavaScript
import { initializeFieldStore } from '../utils';
export function getValue(form, name, { shouldActive = true, shouldTouched = false, shouldDirty = false, shouldValid = false, } = {}) {
// Get store of specified field
const field = initializeFieldStore(form, name);
// Continue if field corresponds to filter options
if ((!shouldActive || field.active.value) &&
(!shouldTouched || field.touched.value) &&
(!shouldDirty || field.dirty.value) &&
(!shouldValid || !field.error.value)) {
// Return value of field
return field.value.value;
}
// Otherwise return undefined
return undefined;
}