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
Can't add external results with Composition API #1147
Comments
Hi Louis-kevin, const externalServerValidation = () => true
const rules = {
field: { externalServerValidation},
otherField: { externalServerValidation }
}
const state = {
field: null,
otherField: null}
const v$ = useVuelidate(rules, state, { $external..... you probally know what to do next}) |
Thanks for the response @PaulMenheere Also, I stamble in this problem when I was trying to create components with default rules, but even if I add the workaround, it seems that the child component does not have the error and only the parent vuelidate has the error I created this example, to reproduce the error I don't really know if its by design, a bug or a new feature Can you guys enlighten me @dobromir-hristov @shentao ? |
Here a code example: // Child.vue
const props = defineProps({ modelValue: {} });
const inputChild = ref(props.modelValue);
const rules = {
inputChild: {
required,
},
};
const v = useVuelidate(rules, { inputChild });
// The main idea here is: this vuelidate instance receive the external validation from parent vuelidate instance // Parent.vue
const state = reactive({
inputInParent: "asdfsd",
inputChild: "asdf",
});
const $externalResults = reactive({});
const externalServerValidation = () => true;
const rules = {
inputInParent: { required },
inputChild: { externalServerValidation }, // Better if I don't need to declare the child rules
};
const v = useVuelidate(rules, state, { $externalResults });
// validate method
async function validate() {
if (!(await v.value.$validate())) return;
const errors = {
inputInParent: "Error in inputInParent",
inputChild: "Error in input in child",
};
Object.assign($externalResults, errors);
} |
Yup, there seems to be a bug with it not updating the state of the errors for validation, even though it's there. The docs are simply wrong currently. |
So I found an interesting thing - externalResults errors go to $silentErrors. This isn't mentioned anywhere in the documentation. So you have to check boith $errors and $silentErrors (for reasons unbeknownst to me) to get the error output. |
I have the same problem and used |
Describe the bug
When adding external error to vuelidate, it does not add into field
One of the examples I as able to add only to fields that have rules
In other example I just can't add at all
I do not tested in Options API
Reproduction URL
This just does not work at all
This does not work for input without rules
The text was updated successfully, but these errors were encountered: