vantezzen / auto-form

🌟 A React component that automatically creates a @shadcn/ui form based on a zod schema.
https://vantezzen.github.io/auto-form/
MIT License
2.75k stars 99 forks source link

Conditional Logics for Forms #45

Closed matbrgz closed 8 months ago

matbrgz commented 11 months ago

Feature Suggestion

Description

I'd like to propose a new feature that enables Conditional Logics for Forms in the AutoForms component. This feature would allow users to dynamically render fields based on predefined rules within the AutoForms component.

Technical Details

Implementation Suggestions

To implement this feature, we can follow these steps:

  1. Define Condition Rules: Within the AutoForms component, users can define condition rules that specify when a field should be displayed or hidden based on the values of other fields.

  2. Evaluate Conditions: When a user interacts with the form (e.g., by typing in an input field), the AutoForms component will evaluate the condition rules to determine if any fields should be dynamically rendered or hidden.

  3. Dynamic Rendering: If a condition evaluates to true, the corresponding field will be dynamically rendered; if it evaluates to false, the field will be hidden.

  4. React State Management: Use React state (e.g., useState or useReducer) to manage the dynamic rendering of fields based on the condition rules.

  5. Update Form State: Ensure that the form state accurately reflects the values of all visible fields, even if some are dynamically rendered based on conditions.

Additional Notes

This feature would greatly enhance the flexibility and customization options available to users of the AutoForms component. It would allow for more dynamic and context-aware form rendering.

Looking forward to your feedback on this suggestion!

Best regards,

vantezzen commented 8 months ago

Basic functionality implemented via the new dependencies option