Manages Roqueform field initial value and dirty status.
npm install @roqueform/reset-pluginManages Roqueform field initial value and dirty status.
``sh`
npm install --save-prod @roqueform/reset-plugin
š API documentation is available here.
Update the initial value of a field:
`ts
import { createField } from 'roqueform';
import { resetPlugin } from '@roqueform/reset-plugin';
const planetField = createField({ name: 'Pluto' }, resetPlugin());
planetField.setInitialValue({ name: 'Mars' });
planetField.at('name').initialValue;
// ā® 'Mars'
`
The field is considered dirty when its value differs from the initial value. Values are compared using an equality
checker function passed to the resetPlugin. By default, values are compared using
fast-deep-equal.
`ts`
planetField.at('name').isDirty // ā® true
Get the array of all dirty fields:
`ts``
planetField.getDirtyFields();
// ā® [planetField.at('name')]