@modular-forms/qwik
Version:
The modular and type-safe form library for Qwik
21 lines (20 loc) • 747 B
JavaScript
import { getFieldStore } from '../utils';
/**
* Checks if the specified field is included in the form.
*
* @param form The form of the field.
* @param name The name of the field.
* @param options The field options.
*
* @returns Whether the field is included.
*/
export function hasField(form, name, { shouldActive = true, shouldTouched = false, shouldDirty = false, shouldValid = false, } = {}) {
// Get store of specified field
const field = getFieldStore(form, name);
// Return whether field is present and matches filter options
return (!!field &&
(!shouldActive || field.active) &&
(!shouldTouched || field.touched) &&
(!shouldDirty || field.dirty) &&
(!shouldValid || !field.error));
}