(
name: InternalFieldName,
fieldValue: unknown,
isBlurEvent?: boolean,
shouldDirty?: boolean,
shouldRender?: boolean,
)
| 419 | }; |
| 420 | |
| 421 | const updateTouchAndDirty = ( |
| 422 | name: InternalFieldName, |
| 423 | fieldValue: unknown, |
| 424 | isBlurEvent?: boolean, |
| 425 | shouldDirty?: boolean, |
| 426 | shouldRender?: boolean, |
| 427 | ): Partial< |
| 428 | Pick<FormState<TFieldValues>, 'dirtyFields' | 'isDirty' | 'touchedFields'> |
| 429 | > => { |
| 430 | let shouldUpdateField = false; |
| 431 | let isPreviousDirty = false; |
| 432 | const output: Partial<FormState<TFieldValues>> & { name: string } = { |
| 433 | name, |
| 434 | }; |
| 435 | |
| 436 | if (!_options.disabled) { |
| 437 | if (!isBlurEvent || shouldDirty) { |
| 438 | const isCurrentFieldPristine = deepEqual( |
| 439 | get(_defaultValues, name), |
| 440 | fieldValue, |
| 441 | ); |
| 442 | |
| 443 | if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) { |
| 444 | isPreviousDirty = _formState.isDirty; |
| 445 | |
| 446 | _formState.isDirty = output.isDirty = |
| 447 | !isCurrentFieldPristine || _getDirty(); |
| 448 | shouldUpdateField = isPreviousDirty !== output.isDirty; |
| 449 | } |
| 450 | |
| 451 | isPreviousDirty = !!get(_formState.dirtyFields, name); |
| 452 | |
| 453 | if (isCurrentFieldPristine !== _formState.isDirty) { |
| 454 | _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues); |
| 455 | } else { |
| 456 | isCurrentFieldPristine |
| 457 | ? unset(_formState.dirtyFields, name) |
| 458 | : set(_formState.dirtyFields, name, true); |
| 459 | } |
| 460 | |
| 461 | output.dirtyFields = _formState.dirtyFields; |
| 462 | shouldUpdateField = |
| 463 | shouldUpdateField || |
| 464 | ((_proxyFormState.dirtyFields || |
| 465 | _proxySubscribeFormState.dirtyFields) && |
| 466 | isPreviousDirty !== !isCurrentFieldPristine); |
| 467 | } |
| 468 | |
| 469 | if (isBlurEvent) { |
| 470 | const isPreviousFieldTouched = get(_formState.touchedFields, name); |
| 471 | |
| 472 | if (!isPreviousFieldTouched) { |
| 473 | set(_formState.touchedFields, name, isBlurEvent); |
| 474 | output.touchedFields = _formState.touchedFields; |
| 475 | shouldUpdateField = |
| 476 | shouldUpdateField || |
| 477 | ((_proxyFormState.touchedFields || |
| 478 | _proxySubscribeFormState.touchedFields) && |
no test coverage detected
searching dependent graphs…