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

Radio box does not work correctly inside repeater field #434

Open
XGhozt opened this issue May 24, 2021 · 10 comments
Open

Radio box does not work correctly inside repeater field #434

XGhozt opened this issue May 24, 2021 · 10 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
Milestone

Comments

@XGhozt
Copy link

XGhozt commented May 24, 2021

Recreation:
https://codesandbox.io/s/vue-formulate-reproduction-template-forked-k5kpr?file=/src/components/Reproduction.vue

For now my solution is to use a select field instead. But the problem appears to be that the name of the field is the same for every single instance so your browser won't let you select more than one.

@XGhozt XGhozt added the bug report A submitted bug report, not yet validated. label May 24, 2021
@justin-schroeder justin-schroeder added this to 3.0.0 in Roadmap May 29, 2021
@justin-schroeder justin-schroeder added this to the 3.0.0 milestone May 29, 2021
@justin-schroeder
Copy link
Member

Ah yeah, that's an issue for sure — we;ve actually seen this before in our own work. The way we solved it was by using the index from the #default slot and appending it to the name of the input. Kinda hacky, but it works. I'm honestly not sure what the "right" thing to do here is. It might make sense to use formData style names with square brackets []. I'll tag this as somethign to look into doin out of the box in 3

@gazben
Copy link

gazben commented Jul 30, 2021

@justin-schroeder What if you add a <form> tag around the input group?

@justin-schroeder
Copy link
Member

@gazben then you have multiple forms with multiple submission events, accessibility concerns etc etc etc. I know there are some stack overflow answers that say this is a good idea but I'm less convinced. I think we need a good way to do this out of the box, not sure if we should re-map the names or maybe use synthetic radios...not sure.

@gazben
Copy link

gazben commented Aug 2, 2021

@justin-schroeder I know it can introduce other problems, but this is just an input, and if you suppress the form tag events, it should work (this was my workaround).

But I think the most important thing here would be, to add a warning to the docs, because for repeating fields, I think this behaviour is not obvious.

@justin-schroeder
Copy link
Member

@gazben yep, I agree should be a note in the docs about it. Would you want to submit a PR to the docs with a tip block about it?

@justin-schroeder justin-schroeder added bug Something isn't working documentation Improvements or additions to documentation and removed bug report A submitted bug report, not yet validated. labels Aug 2, 2021
@BennaceurHichem
Copy link

@justin-schroeder is their any updates about this issue, I'm currently facing the same issue, thank you 💯

@justin-schroeder
Copy link
Member

No updates at the moment, but you can get around it by changing the name of the radio input in each group by concatenating the index of the group (extracted from the slot)

@JackEdwardLyons
Copy link

JackEdwardLyons commented Nov 11, 2021

I've noticed that the index gets out of sync when you delete an item in between a bunch of items.
For example,

  • If I have an array of items with name attributes using the index ... for example ['item-1', 'item-2', 'item-3']
  • If I then I go and delete item-2
  • The array will then be ['item-1', 'item-3']

While this is logical, it's not actually a true representation of the index anymore. if I save this to the DB and reload the page, my data is out of sync.

What should actually happen is that item-3 changes to item-2 as soon as the item-2 is deleted.

Is there a way around this?

@rowild
Copy link

rowild commented Nov 11, 2021

@JackEdwardLyons How do you define the index? If the :key item-xy is something that is defined on the object, then this will not change (and must not change, since it is part of the data item). If, however, a separate index is used, then the index should change...

// this (yours?)
v-for="item in items" :key="item-id"

// vs this
v-for="(item, index) in items" :key="index"
// `index` should adapt after an item has been deleted

@JackEdwardLyons
Copy link

JackEdwardLyons commented Nov 11, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
Roadmap
FormKit
Development

No branches or pull requests

6 participants