Dynamic Options for select based on other form field #904
Replies: 22 comments
-
@jinxac You have multiple options:
|
Beta Was this translation helpful? Give feedback.
-
@rvsia first option is much neat I feel. Thank you for such prompt and helpful replies over the last few days. It has been a really great help for me :) |
Beta Was this translation helpful? Give feedback.
-
@jinxac No problem! That's the reason why we are here! :) |
Beta Was this translation helpful? Give feedback.
-
@rvsia I was trying out the third scenario( |
Beta Was this translation helpful? Give feedback.
-
@rvsia so my requirement here is as follows:-
I think FormSpy will be a good use case for this. Is there a way I can achieve this? |
Beta Was this translation helpful? Give feedback.
-
@jinxac Yeah, you have probably missed to set-up the subscription prop as it's mentioned in the documentation page. The problem is that other fields are not being refreshed when some other is being changed (due to optimization.) You can setup a If you encounter this issue, you can use FormSpy component to just wrap the select you need:
|
Beta Was this translation helpful? Give feedback.
-
@rvsia The way I was thinking to handle Pincode logic is to do the following:-
Is this a clean way to do it or is there any other way I can achieve this? My concern here is still how to change options on the fly. I cannot hardcode the options in schema this way as they are coming from the API |
Beta Was this translation helpful? Give feedback.
-
@jinxac You could use |
Beta Was this translation helpful? Give feedback.
-
Interesting, I will explore it once. In the meantime, I was thinking if I do the following I might be able to solve this:-
I think this should work fine, right ? |
Beta Was this translation helpful? Give feedback.
-
@jinxac Sounds good! |
Beta Was this translation helpful? Give feedback.
-
@rvsia I have made a demo at https://codesandbox.io/s/priceless-booth-7htyr in case someone encounters on the same issue. |
Beta Was this translation helpful? Give feedback.
-
I was thinking about adding a section with custom components examples to the docs. @rvsia do you have a couple of minutes to prepare the new docs section? @jinax could then add his example to it. |
Beta Was this translation helpful? Give feedback.
-
@jinxac Awesome! Thanks. @Hyperkid123 I was thinking about the same thing! But right now I don't have much spare time as I am mentally preparing to update tests for 50 changed files in Sources. We can do it next week. |
Beta Was this translation helpful? Give feedback.
-
@rvsia Sure can you drop a comment here whenever we are ready?. I can add my examples post that. |
Beta Was this translation helpful? Give feedback.
-
All right. I might have a few minutes after lunch. @jinxac we will let you know. |
Beta Was this translation helpful? Give feedback.
-
@jinxac the example section is ready. You can follow this guide to add yours: https://data-driven-forms.org/development-setup#addingformcomponentexample There is also a sample example page already added. Feel free to override it if you want. The development setup should give you all the information you need to setup local development. We required node v10 in order to run, build, and deploy the docs (hosting limitation) so make sure you have the correct version. You can use nvm to install and switch between node versions. |
Beta Was this translation helpful? Give feedback.
-
@Hyperkid123 looking into it. Will do it asap |
Beta Was this translation helpful? Give feedback.
-
@rvsia @Hyperkid123 I had integrated the above with a few of my forms and it works fine until FieldArray came into the picture :D. While using SpyProps, Now the problem here is that the name of the prop which comes for field array is nested. For example, in my case, it comes as In the case of render props for fieldArray field, how do I access the indexes for a particular row? I have created mappers to handle such scenarios using a splitting algorithm based on Is there a better way to do it? |
Beta Was this translation helpful? Give feedback.
-
@rvsia @Hyperkid123 can someone please help me :) ? |
Beta Was this translation helpful? Give feedback.
-
@jinxac sorry your comment slipped through my notifications. I will try to look at your issue later today. |
Beta Was this translation helpful? Give feedback.
-
@jinxac I do apologize I was not able to get to this yesterday :( . Could you post us a code sample from your solution? I think that using the name is the right way to go. It will always give you the correct information. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I also think that splitting the name is the only way how to do it. |
Beta Was this translation helpful? Give feedback.
-
Scope: Form Renderer
Description
I have a case in which I need to change select options for an input called relationship based on a gender field. For example, in the case where gender is male the options for relationships should change.
Can someone please help me? TIA
Beta Was this translation helpful? Give feedback.
All reactions