-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conditional example #181
Comments
So for conditional fields you should really read on this thread, where we discussed a strategy to rerender a form against a new schema computed against its updated formData. It seems it worked for @mplis-jetsetter, maybe (s)he could share a snippet? |
Thanks, I rewrote my example to https://jsfiddle.net/kaihendry/7fb0vyzx/ following your suggestion. It's a few lines less & I think it makes sense. wdyt? |
Looks good! I'd probably avoid mutating the schema, passing a clone, but otherwise works great anyway :) Can I close the issue? |
There is a problem I can't quite figure out as yet. How to reset the schema once false is selected after true. https://jsfiddle.net/kaihendry/7fb0vyzx/4/ |
That's why I suggested to keep the original schema around and avoid mutating it. Basically when false is selected again, you should revert to your original schema value (eg. in an |
Yes, I am trying to do this. I'm only mutating |
I'm gonna try updating your gist and see how it goes. |
Here's a working example leveraging es7 object properties spread operator: https://jsfiddle.net/ap932fus/2/ |
I don't quite understand why a spread operator was required. Why was the schema not being updated in my fiddle? https://jsfiddle.net/kaihendry/7fb0vyzx/4/ |
|
If you plan on dealing with immutability a lot, you should look at Immutable.js which offers a nice API for handling immutable structures. But the spread operator route is nice too. |
May I close the issue now? |
You can close the issue, but I am still a bit confused how I'm a little worried that maintaining the schema will be very tricky when there is several conditional paths. |
This is really matter of finding a good architecture and code organisation, where atomic idempotent functions and a good understanding of how js mutability works are key. I'm closing this issue. |
Oh, and as a last tip, you might be interested in using redux to maintain your form state; it provides convenient helpers to update state along a good code layout so state handling code scales better. |
Thank you I will look into Redux. One more thing I don't quite understand is how on Line 43, the formData of at least "name" is passed without explicitly saying so: https://jsfiddle.net/kaihendry/9cgj23e7/6/ Maybe this is some artefact of React, but I expected the two Form elements to be isolated. |
@kaihendry I don't have an answer for your most recent question, though I can suggest that you try following through this function which is called from here. That might explain why the Form is using old formData but I'm not 100% sure. However, I can give you a bit of advice that will hopefully allow you to avoid some of the issues I've run into while trying to solve a similar problem to the one you're working on here. I'm using Reflux to store the schema, uiSchema, and formData that I use to render the form. When I want to make a change to the form, I update the store, which triggers a re-rendering. My advice is to avoid mutating data as much as possible - always work with a new copy. I ran into an issue where I was mutating the |
This pretty much sums it up :) Be careful with JSON serialization/deserialization as it can get quickly quite expensive. |
Description
Carrying on from #151
I need to express if "needG" show "gschema" example.
Steps to Reproduce
I just want to check with you that I have done this the "right way". Since I really don't understand how a custom Field would look like.
The text was updated successfully, but these errors were encountered: