最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - Nested Object Yup and Form Primevue - Stack Overflow

programmeradmin0浏览0评论

I tried to create a simple validation in vue js using primevue and yup:

<script setup>
import { Form, FormField } from '@primevue/forms';
import { useToast } from 'primevue/usetoast';

import { yupResolver } from '@primevue/forms/resolvers/yup';
import * as yup from 'yup';

const toast = useToast();
const formStore = useFormStore();

const formData = reactive({
    frequencies: {
        frequencyType: '',
        frequencyDays: [],
        frequencyWeeks: [],
        frequencyTimes: [
            {
                frequencyTimeValue: '',
                frequencyTimeMaxDuration: ''
            }
        ]
    },
});

const resolver = yupResolver(
    yup.object({
          frequencies: yup.object({
            frequencyType: yup.string().required('Checking Frequency is required.')
        })
    })
);
</script>
<template>
    <Form :initialValues="formData" :resolver @submit="onFormSubmit" class="flex flex-col gap-2 w-full">
 <FormField v-slot="$field" name="frequencies.frequencyType" class="flex flex-col gap-1">
                            <label for="frequencyType" class="block text-sm font-medium">Checking Frequency</label>
                            <Select v-model="formData.frequencies.frequencyType" :options="frequencyOptions" optionValue="value" optionLabel="label"
                                class="w-full" :invalid="$field.invalid" />
                            <Message v-if="$field.invalid" severity="error" size="small" variant="simple">
                                {{ $field.error?.message }}
                            </Message>
                        </FormField>
 </Form>
</template>

The problem is error warning doesn't appear, but if i change name="frequencyType" and also change the nested object become flatten, it's worked. Any suggestion?

I tried to create a simple validation in vue js using primevue and yup:

<script setup>
import { Form, FormField } from '@primevue/forms';
import { useToast } from 'primevue/usetoast';

import { yupResolver } from '@primevue/forms/resolvers/yup';
import * as yup from 'yup';

const toast = useToast();
const formStore = useFormStore();

const formData = reactive({
    frequencies: {
        frequencyType: '',
        frequencyDays: [],
        frequencyWeeks: [],
        frequencyTimes: [
            {
                frequencyTimeValue: '',
                frequencyTimeMaxDuration: ''
            }
        ]
    },
});

const resolver = yupResolver(
    yup.object({
          frequencies: yup.object({
            frequencyType: yup.string().required('Checking Frequency is required.')
        })
    })
);
</script>
<template>
    <Form :initialValues="formData" :resolver @submit="onFormSubmit" class="flex flex-col gap-2 w-full">
 <FormField v-slot="$field" name="frequencies.frequencyType" class="flex flex-col gap-1">
                            <label for="frequencyType" class="block text-sm font-medium">Checking Frequency</label>
                            <Select v-model="formData.frequencies.frequencyType" :options="frequencyOptions" optionValue="value" optionLabel="label"
                                class="w-full" :invalid="$field.invalid" />
                            <Message v-if="$field.invalid" severity="error" size="small" variant="simple">
                                {{ $field.error?.message }}
                            </Message>
                        </FormField>
 </Form>
</template>

The problem is error warning doesn't appear, but if i change name="frequencyType" and also change the nested object become flatten, it's worked. Any suggestion?

Share Improve this question asked Feb 4 at 8:24 YMRPYMRP 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Seem to be a PrimeVue issue :

https://github/primefaces/primevue/issues/6924

https://github/primefaces/primevue/issues/7075

fixed here :

https://github/primefaces/primevue/commit/536d21cef153416c665f728ee04012a0c492ae69

发布评论

评论列表(0)

  1. 暂无评论