You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This behaviour isn't necessarily a bug – I understand why it happens, and what the workaround for it is, but I wanted to flag it for visibility and in case anybody has the time and willingness to work on a solution.
Then if we create a changeset around an instance of MyClass (with count set to 0 and shouldValidateCount set to true) using those validations, the following happens:
(asyncfunctionshowValidationGotcha(){awaitchangeset.validate();console.log(changeset.get('isValid'));// falsechangeset.set('shouldValidateCount',false);console.log(changeset.get('isValid'));// false, when really should be true})();
We can of course work around this by explicitly calling changeset.validate() or changeset.validate('count') whenever shouldValidateCount gets set to a new value, but this is clunky and easily forgotten – and gets hard to manage when an object has a large number of conditional validations.
I'm not familiar with the internals of tracked properties etc., but it'd be awesome if it was possible to tap into a mechanism like that to ensure that the validations for properties with conditions associated with them get recomputed whenever a dependency of that condition is updated 🤔
The text was updated successfully, but these errors were encountered:
This behaviour isn't necessarily a bug – I understand why it happens, and what the workaround for it is, but I wanted to flag it for visibility and in case anybody has the time and willingness to work on a solution.
Suppose we have a class like
and validations for that class like
Then if we create a changeset around an instance of
MyClass
(withcount
set to0
andshouldValidateCount
set totrue
) using those validations, the following happens:We can of course work around this by explicitly calling
changeset.validate()
orchangeset.validate('count')
whenevershouldValidateCount
gets set to a new value, but this is clunky and easily forgotten – and gets hard to manage when an object has a large number of conditional validations.I'm not familiar with the internals of tracked properties etc., but it'd be awesome if it was possible to tap into a mechanism like that to ensure that the validations for properties with conditions associated with them get recomputed whenever a dependency of that condition is updated 🤔
The text was updated successfully, but these errors were encountered: