Skip to content

Commit

Permalink
fix: fixed behaviour with $autoDirty and $rewardEarly when depend…
Browse files Browse the repository at this point in the history
…ency change
  • Loading branch information
victorgarciaesgi committed Dec 14, 2024
1 parent 8514474 commit 876f349
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export function createReactiveFieldStatus({
$pending: scopeState.$pending,
$valid: scopeState.$valid,
},
modifiers: {
$autoDirty: scopeState.$autoDirty,
$rewardEarly: scopeState.$rewardEarly,
},
customMessages,
rule: ruleRef as any,
ruleKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ interface CreateReactiveRuleStatusOptions {
$valid: Readonly<Ref<boolean>>;
$error: Readonly<Ref<boolean>>;
};

modifiers: {
$rewardEarly: ComputedRef<boolean | undefined>;
$autoDirty: ComputedRef<boolean | undefined>;
};
customMessages: CustomRulesDeclarationTree | undefined;
path: string;
storage: RegleStorage;
Expand All @@ -43,6 +46,7 @@ export function createReactiveRuleStatus({
path,
storage,
$debounce,
modifiers,
}: CreateReactiveRuleStatusOptions): $InternalRegleRuleStatus {
type ScopeState = {
$active: ComputedRef<boolean>;
Expand Down Expand Up @@ -172,7 +176,11 @@ export function createReactiveRuleStatus({
} satisfies ScopeState;
})!;

$unwatchState = watch(scopeState.$params, $validate);
$unwatchState = watch(scopeState.$params, () => {
if (modifiers.$autoDirty.value || (modifiers.$rewardEarly.value && fieldProperties.$error.value)) {
$validate();
}
});
}

$watch();
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/useRegle/properties/$autoDirty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
shouldBeValidField,
} from '../../../utils/validations.utils';

// TODO add test case for dependency change

describe.each([
['local modifier', simpleNestedStateWithMixedValidation],
['global modifier', simpleNestedStateWithMixedValidationAndGlobalConfig],
Expand Down

0 comments on commit 876f349

Please sign in to comment.