-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rendering a form multiple times in the same view results in ID clashes #447
Comments
@chawes13 this is an interesting problem. The solution you proposed seems like the best way to go. I had assumed that non-dynamic IDs were preferred over dynamic ones but it looks like that just isn't the case (https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id):
Given that info, my only concern would be making sure default styles worked with the new IDs. And this would probably be a breaking change, if an app has any styles relying on the current ID naming scheme. For a short-term workaround, the route of adding unique IDs to a form shouldn't be too time-consuming if you use a consistent prefix: function MyForm ({ form }) {
const uniqueId = (inputName) => form + '-' + inputName
...
<Field name="firstName" id={ uniqueId('firstName') } ... />
} |
@dpikt What process should we use for including the fix for this issue in an upcoming major release? E.g., create an Asana task? Unfortunately it is pretty time consuming. Every step in the survey renders multiple forms (sometimes the same form, sometimes different forms). Both scenarios run the risk of having an ID conflict. function ContactForm () {
// ...
<Field name="name" ... />
}
function ProgramForm () {
// ...
<Field name="name" ... />
}
function SurveyStep () {
return (
<>
<ContactForm />
{programs.map((p) => <ProgramForm key={p.id} .. />}
</>
} The former scenario makes it so that the
|
Wouldn't form names still be unique in the first scenario since redux-form requires a unique key? As far as resolving goes, I think a PR just for this issue would be sufficient. You could probably resolve the input error issue by allowing the auto-generated ID to be overridden and passing it in via LabeledField if you wanted to avoid a breaking change. |
🤦 right, right of course. Thanks for the clarification! |
@dpikt Unfortunately this approach does not work on This behavior may be able to be extracted into a separate, isolated issue as I do not think we want this behavior in any circumstance. Thoughts? |
@chawes13 agreed, that issue is separate. |
Issue
For example, the "Name" input is read 6 times on this view: https://share.getcloudapp.com/KouwQ51p & https://share.getcloudapp.com/YEuyvYJA
Potential Enhancement
react-uid
to append a unique id to the input's name by defaultWorkarounds
FormSection
contraints
,submitFilters
, etc. to be dynamic generatedThe text was updated successfully, but these errors were encountered: