-
Notifications
You must be signed in to change notification settings - Fork 92
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
Passing react element as label causes "Converting circular structure to JSON" error. #82
Comments
Hi @tappleby -- thanks for your report and summary of approaches, that is helpful. You may know already, but you can manually pass in an |
I may use something like this when label isn't hashable: https://gist.github.com/gordonbrander/2230317 |
Yeah I'm using id in a few spots already to get around this. It's a pain to go back and add them to every input though. The challenge with random IDs is making sure they only are generated once per component instead of every render. |
Point taken about random IDs.
Thinking aloud, other solutions might be:
|
Yea im not a fan of the Option 2 seems like it could work fine, is the hashed label approach used instead of something like this to handle server rendered markup? react-intl does have another syntax which would also work but its kinda of annoying to convert every form element to:
|
Think this may be better solved with help from the mothership. |
That looks like it would fix it. my only concern is how soon it would get merged. |
Yes, good point. I guess you could go to the PR and 👍 it. @Semigradsky do you have an opinion on christianalfoni/formsy-react#367 ? Is there a chance this will be merged? |
@tappleby your concerns about time to merge were well founded. Pinging the awesome @aesopwolf to get an opinion on this PR 😸. |
Why not just delete |
Hello there @aesopwolf. In plain old HTML, it's possible to have multiple controls in the same If not, we need something to add uniqueness for getting an ID for the component; I chose |
Ah you're right. I was under the impression that the
I suppose you could use |
Yea name wont be unique enough, especially if you have multiple form on page. Challenge with In my fork of FRC I ended up defaulting just to name but adding the option to provide a custom uid generator We just use a static counter in our app: let counter = 0;
function generateFieldUid(name) {
return `frc-${name}-${counter++}`;
} |
I was thinking about it, since My vote is to still delete |
Hrm, yea I guess formsy-react doesn't have the same limitations as the standard form API... Since ids are global I could still see running into conflicts if 2 different forms with same name inputs are on the page. Could formsy-react support / generate a unique id for the form itself? Could use to prefix the input id. |
You're right... The issue that arises when 2+ different forms with the same name inputs are on the page is a matter of clicking the label and expecting it to focus the input nearby but instead it will focus the first input field on the page with a matching name. The same behavior would happen in traditional html. So that's more of a developer error than anything. I suppose library code could be written in formsy-react or even formsy-react-components to protect against this case. I'm not a fan though. I don't think the goal is to prevent people writing bad/invalid code. |
Thanks for the feedback, I'm inclined to go along the route of just nuking the It's pretty easy to ensure unique If users really want to have to components with the same |
This is similar to #33, I am trying to use react-intl components for translating the form labels, but the issue will happen for any react element:
This issue is caused by the
JSON.stringify(label)
in the component.getId mixinI have a few ideas around fixing this, but not sure the best approach to take:
React.isValidElement
returnsfalse
It would be nice if we could generate a unique id for each
Formsy.Form
component, then hashing the label wouldnt be necessary. Was thinking we could maybe opt into this using the parent context mixin.The text was updated successfully, but these errors were encountered: