Skip to content
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

how to handle dependent field props? #21

Open
christopherGdynia opened this issue Jan 5, 2023 · 5 comments
Open

how to handle dependent field props? #21

christopherGdynia opened this issue Jan 5, 2023 · 5 comments
Labels
enhancement New feature or request in progress is currently being worked on

Comments

@christopherGdynia
Copy link

In some forms, field props are dependen on values from other fields.

How are we going to solve this?

this could be quiet tricky


A solution for now is creating a custom component, which is dependent and loading the formState from the context (when implemented).

This should be documented. :D

@iway1
Copy link
Owner

iway1 commented Jan 5, 2023

Are you talking about situations where you need to compare things like a password and confirm password field (IE dependent validation steps)? If so, I agree it should be documented. You can use the zod schemas .refine method to do this.

If you're trying to do things like "Hide certain inputs when a certain drop down value is selected", I believe this is possible with an object schema at the moment but might not be a super smooth developer experience? Might be worth adding a more elegant way to deal with these situations...

Let me know some more details on your use case

@christopherGdynia
Copy link
Author

I am talking about passing props like min or max to fields which will have the value ofher fields

We have a use case where the user needs to pick three dates, the value of the first date is passed as the min value to the second date field

@iway1
Copy link
Owner

iway1 commented Jan 6, 2023

@christopherGdynia Ah okay thanks for the info - I would recommend using an object schema for this right now I think, or just writing plain old JSX for these more complex forms.

For the future, I think there's an API that could simplify this though that could be added. We could add a feature where props can be calculated from form state by passing a function instead of an object:

return (
  <Form
    props={(fieldValues)=>({
      endDateSelect: {
        minDate: fieldValues.startDate
      }
    })}
  />
)

Would this suffice, I think it'd cover this use case pretty well?

@christopherGdynia
Copy link
Author

@iway1,
this would be sufficient,

maybe pass as second parameter the form state, with error state.

@iway1
Copy link
Owner

iway1 commented Jan 10, 2023

@christopherGdynia good idea, we'll pass the error state as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in progress is currently being worked on
Projects
None yet
Development

No branches or pull requests

2 participants