-
Hello , export interface IContinentTranslation {
area:number,
[lang: string]: {
id?: string | null;
name: string;
locale: string;
}
} my template html <template>
<div class="mt-2">
<div>
<div class="mb-2">
<span class="form-label">Translation of names *</span>
</div>
<div class="max-h-56 overflow-y-auto ">
<div class="flex items-start gap-5 mb-5" v-for="selectedLanguage in selectedLanguages"
:key="selectedLanguage">
<div class="flex items-center w-2/3">
<div class="flex items-center w-full">
<input v-model="translations[selectedLanguage].name" type="text" id="title" class="form-input mr-2"
placeholder="Name"
required>
</div>
<small>{{ errors }}</small>
</div>
</div>
</div>
</div>
</div>
</form>
</template> my script : const selectedLanguages = ref<string[]>(['en']);
const initialValues = {
area:0,
translations: {
'en': {
name: '',
locale: 'en'
}
}
}
const {errors} = useForm({
validationSchema: {
area: yup.number().required().positive().min(1000),
translations: yup.lazy(value => {
if (value !== undefined) {
return yup.object().shape({
id: yup.string().notRequired(),
name: yup.string().required().max(30).min(2),
locale: yup.string().required().max(2).min(2),
});
}
return yup.mixed().required();
}),
},
initialValues,
})
const {value: area, errorMessage: areaError} = useField<number>("area");
const {value: translations} = useField<IContinentTranslation>("translations"); but i don't why it doesn't work , it doesn't shiow errors about fields |
Beta Was this translation helpful? Give feedback.
Answered by
logaretm
Aug 7, 2022
Replies: 2 comments 10 replies
-
You need to use const {errors} = useForm({
validationSchema: yup.object({
area: yup.number().required().positive().min(1000),
translations: yup.lazy(value => {
if (value !== undefined) {
return yup.object().shape({
id: yup.string().notRequired(),
name: yup.string().required().max(30).min(2),
locale: yup.string().required().max(2).min(2),
});
}
return yup.mixed().required();
}),
}),
initialValues,
}) If the problem persists, please create an example on stackblitz. |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
kevinG73
-
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use
yup.object
to define the schema.If the problem persists, please create an example on stackblitz.