-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sameAs doesn't work #1218
Comments
Same issue. Is there any update? Thank you. |
To resolve my issue, I just created a custom validation to check if the password is same to confirm password. |
@m3c0d322 yea, the only solution is to use custom validation |
@GalacticHypernova it's because you're using it in the wrong way. You can only pass In your particular example this is the only way for it to work (at least I didn't find any other): const form = reactive({
f1: "",
f2: "",
});
const v$ = useVuelidate({
f1: { required },
f2: { sameAsF1: sameAs(computed(() => form.f1)) },
}); Not sure why f2: { sameAsF1: sameAs(toRef(form.f1)) }, Also, if you hardcode your value to be a const f2Hardcoded = ref('test')
const form = reactive({
f1: "",
f2: "",
});
const v$ = useVuelidate({
f1: { required },
f2: { sameAsF1: sameAs(f2Hardcoded) },
}); |
Well, this does seem a little too overcomplicated with a bit too much boilerplate, and there's the very valid concern of data leaks when needing to create more reactive objects than necessary.. But thanks anyway for the workaround! |
Well, I both agree and disagree :) Agreed, it looks a bit over-complicated, but at the same time, you need to do such manipulations quite rarely. And I don't really follow your concern about memory leaks – |
TLDR; const form = reactive({
password: '',
password_confirmation: '',
email: '',
})
const rules = {
email: { email, required },
password: { required, minLength: minLength(3) },
password_confirmation: { required, sameAs: sameAs(computed(() => form.password)) },
}
const v$ = useVuelidate(rules, form) |
Using Vue with Nuxt here. My solution was to just do a custom validation: sameAsPassword: helpers.withMessage(t('validations.sameAsPassword'), function (value: string) {
return value === state.password
}), |
I apologize for.the comically late response, I completely forgot about this. The reason I was talking about data leaks is because I have different uses for this, including something in an async context (after await). And I know some vue internals get funky when that happens, prime example being watchers not being auromatically stopped and unregistered, which would reult in a mem leak if you don't manually stop them. I'm not necessarily saying that it would for sure break anything, but I do not know how it would behave which could result in some peculiar edge cases. |
I also opted for a custom validation with a simple computed property. As it turns out, sometimes using the frameworks core features is the ideal option can save much of the abstraction overhead and complexity =) |
Describe the bug
Using sameAs according to the documentation doesn't seem to work, not as a string and not as a ref.
Reproduction URL
This can be seen in any composition API project that uses vuelidate sameAs (specifically tested with Nuxt 3.8.2)
Didn't have time to make a reproduction as I'm currently not home, if needed I'll gladly provide it when I get the chance.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
sameAs should work correctly.
Screenshots
Inapplicable, the red outline is simply a design choice of mine, adding any sort of color to it will prompt it.
Additional context
The text was updated successfully, but these errors were encountered: