UNPKG

@modular-forms/solid

Version:

The modular and type-safe form library for SolidJS

24 lines (23 loc) 742 B
import { batch, untrack } from 'solid-js'; import { isFieldDirty } from './isFieldDirty'; import { updateFormDirty } from './updateFormDirty'; /** * Updates the dirty state of a field. * * @param form The form of the field. * @param field The store of the field. */ export function updateFieldDirty(form, field) { untrack(() => { // Check if field is dirty const dirty = isFieldDirty(field.startValue.get(), field.value.get()); // Update dirty state of field if necessary if (dirty !== field.dirty.get()) { batch(() => { field.dirty.set(dirty); // Update dirty state of form updateFormDirty(form, dirty); }); } }); }