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
If we want to implement a form "reset to defaults values", there's no way to do it without making all validators run on previous value set — either via $model or the reactive form mutation. This is particularly useful if you have async validators that do any sort of API requests. Resetting to a previous value will still trigger the useless API request and currently there's no easy way to prevent it without manually fiddle/hacking your configs.
Solution
The first one that comes to my mind is imitate vee-validate. With the current api, make $reset method accept a value argument and if that value is present (!== undefined) do not run any validators when field model is set, aside from marking the field $dirty as false.
The second one would be a new method $slientSetModel our $silentModelcomputed setter that performs the same thing.
Alternative
I've noticed that is possible to achieve this if we activate $lazy on the useVuelidate hook level (it doesn't work on validator level config), and then do a combination of $reset() plus mutate the reactive form directly (not the $model). In my case, activating this breaks a lot of specs so I would have to patch a lot of things just to get something that could be available without any config limitation.
This should be possible to do because $rewardEarly does exactly that. It prevents validators to run until $commit is called. In my case I cannot set this validation mode.
Final thoughts
Would be nice to have a way to do it regardless of the config, resetting values programatically is fairly common form scenario.
The text was updated successfully, but these errors were encountered:
Problem
If we want to implement a form "reset to defaults values", there's no way to do it without making all validators run on previous value set — either via
$model
or the reactiveform
mutation. This is particularly useful if you have async validators that do any sort of API requests. Resetting to a previous value will still trigger the useless API request and currently there's no easy way to prevent it without manually fiddle/hacking your configs.Solution
The first one that comes to my mind is imitate
vee-validate
. With the current api, make$reset
method accept a value argument and if that value is present (!== undefined
) do not run any validators when field model is set, aside from marking the field$dirty
as false.Reference: see #resetField chapter
The second one would be a new method
$slientSetModel
our$silentModel
computed
setter that performs the same thing.Alternative
I've noticed that is possible to achieve this if we activate
$lazy
on theuseVuelidate
hook level (it doesn't work on validator level config), and then do a combination of$reset()
plus mutate the reactiveform
directly (not the$model
). In my case, activating this breaks a lot of specs so I would have to patch a lot of things just to get something that could be available without any config limitation.Demo
Additional context
This should be possible to do because
$rewardEarly
does exactly that. It prevents validators to run until$commit
is called. In my case I cannot set this validation mode.Final thoughts
Would be nice to have a way to do it regardless of the config, resetting values programatically is fairly common form scenario.
The text was updated successfully, but these errors were encountered: