Skip to content
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

Form: v-slot="$form" doesn't handle nested array of objects #6924

Open
jarobober opened this issue Dec 4, 2024 · 3 comments
Open

Form: v-slot="$form" doesn't handle nested array of objects #6924

jarobober opened this issue Dec 4, 2024 · 3 comments
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Milestone

Comments

@jarobober
Copy link

Describe the bug

Couldn't handled properly form data which is object with nested array of objects. Looks like v-slot="$form" doesn't support nested arrays.

That's our form data:
const data = ref({ username: '', emails: [ { title: '', address: '', }, { title: '', address: '', }, ], });

That's what v-slot="$form" returns:
{ "valid": true, "username": { "value": "", "touched": false, "dirty": false, "pristine": true, "valid": true, "invalid": false, "error": null, "errors": [] }, "title": { "touched": false, "dirty": false, "pristine": true, "valid": true, "invalid": false, "error": null, "errors": [] }, "address": { "touched": false, "dirty": false, "pristine": true, "valid": true, "invalid": false, "error": null, "errors": [] } }

Due to that we can't validate it using yup. We are currently introducing PrimeVue into new version of our app so handling nested arrays and objects in forms would be needed.

If there is an alternative way to achieve this, any guidence would be greatly appreciated.
Best regards!

Reproducer

https://stackblitz.com/edit/pgshym?file=src%2FApp.vue

PrimeVue version

4.2.4

Vue version

4.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

Chrome 131.0

Steps to reproduce the behavior

No response

Expected behavior

No response

@jarobober jarobober added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 4, 2024
@saidtaylan
Copy link

Yes. I have tried way @jarobober but i cannot succeed as well. I want to add additional objects dynamically to array and validate it. But i cannot iterate over the loop.

@Mihaszki
Copy link

Mihaszki commented Dec 9, 2024

Yes. Same problem as @jarobober
This is quite important for more complex forms with many inputs.

@arikanaydin
Copy link

arikanaydin commented Dec 9, 2024

Yes, Same problem as @jarobober
`const resolver = ref(
yupResolver(
yup.object().shape({
sourceName: yup.string().required('Source name is required.'),
locales: yup
.array()
.of(
yup.object().shape({
name: yup.string().required('Name is required.'),
})
)
.required('Locales are required.')
.test('all-names-filled', 'All locales must have a name.', (value) => {
return value?.every((locale) => locale.name.trim() !== '');
}),
})
)
);
const initialValues = reactive({
sourceName: "",
locales: languages.value.map((lang) => ({ name: "", code: lang.code })),
})

  <div v-for="(lang, index) in initialValues.locales.sort((a,b) => (a.code > b.code) ? 1 : ((b.code > a.code) ? -1 : 0))" :key="lang.code" class="col-span-3">
    <FloatLabel variant="in">
      <InputText
          :name="`locales[${index}].name`"
          :id="`${lang.code}_name`"
          class="w-full"
          v-model="lang.name"
      />
      <label :for="`${lang.code}_name`">{{ lang.code }} Name </label>
    </FloatLabel>
    <Message
        v-if="($form as any).locales && ($form as any).locales[index]?.name?.invalid"
        severity="error"
        size="small"
        variant="simple"
    >
      {{ ($form as any).locales[index]?.name?.error?.message || 'Invalid value' }}
    </Message>


  </div>

`

@tugcekucukoglu tugcekucukoglu added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 10, 2024
@tugcekucukoglu tugcekucukoglu added this to the 4.3.0 milestone Dec 10, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeVue Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
Status: Review
Development

No branches or pull requests

5 participants