Skip to content

Commit

Permalink
🐞 fix react-hook-form#11287 disabled prop cause const dirtyFields upd…
Browse files Browse the repository at this point in the history
…ate (react-hook-form#11291)

* 🐞 fix react-hook-form#11287 disabled prop cause const dirtyFields update

* fix issue with test
  • Loading branch information
bluebill1049 authored and rafaelcalhau committed May 5, 2024
1 parent 88c8168 commit 1f3ef46
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/logic/createFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export function createFormControl<
const output: Partial<FormState<TFieldValues>> & { name: string } = {
name,
};
const disabledField = get(_fields, name) && get(_fields, name)._f.disabled;

if (!isBlurEvent || shouldDirty) {
if (_proxyFormState.isDirty) {
Expand All @@ -306,13 +307,11 @@ export function createFormControl<
shouldUpdateField = isPreviousDirty !== output.isDirty;
}

const isCurrentFieldPristine = deepEqual(
get(_defaultValues, name),
fieldValue,
);
const isCurrentFieldPristine =
disabledField || deepEqual(get(_defaultValues, name), fieldValue);

isPreviousDirty = get(_formState.dirtyFields, name);
isCurrentFieldPristine
isPreviousDirty = !disabledField && get(_formState.dirtyFields, name);
isCurrentFieldPristine || disabledField
? unset(_formState.dirtyFields, name)
: set(_formState.dirtyFields, name, true);
output.dirtyFields = _formState.dirtyFields;
Expand Down

0 comments on commit 1f3ef46

Please sign in to comment.