vue-generators / vue-form-generator

:clipboard: A schema-based form generator component for Vue.js
MIT License
3k stars 530 forks source link

Having multiple components with radio buttons makes it so that only one of them is visibly selected at a time #695

Open cravindra opened 3 years ago

cravindra commented 3 years ago

If someone can point me to what might be causing this, I'd be happy to raise a PR to help fix it

cravindra commented 3 years ago

On further investigation, it appears to me that the issue is mainly due to the fact the the name attribute on the input[type=radio] element is assigned to this.schema.model which will be the same if multiple instances of the form are rendered with radio buttons which share a model name.

This means that the browser will treat all radio buttons as part of the same radio group. Is there an instance-level value that can be used as a prefix that can fix this?

This can even happen for example if two separate forms use radio buttons which happen to have the same key that they write to.

Potential Fixes:

  1. Introduce an instance-level unique identifier which will default to a random hash which can be used as prefixes for elements which behave like the radio group

  2. At the field level, auto prefix with a randomly generated hash to ensure grouping across instances is respected

Option 2 would have the least impact in terms of API changes.. Will see if I can code it up