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

Conditionally display layout components with its children #14

Open
pharreX19 opened this issue Dec 14, 2022 · 3 comments
Open

Conditionally display layout components with its children #14

pharreX19 opened this issue Dec 14, 2022 · 3 comments

Comments

@pharreX19
Copy link

Is it possible to apply the displayIf component to a layout component, so that the whole component with its children be displayed if the condition is met? Since I have quite a few field components within the layout container its a bit tedious to apply displayIf to every single field component.

@radekmie radekmie self-assigned this Dec 14, 2022
@radekmie
Copy link
Contributor

Hey @pharreX19. The DisplayIf component is just an example that shows how to approach this problem and you don't have to use it as it is presented in the docs but you could implement your own solution using the same idea. Sure, it gets tedious and requires you to write JSX for the form, but there's another way - doing it within a custom AutoField.

Using the AutoField.componentDetectorContext you could inspect the props and context and based on that decide, that this very component should not be rendered (i.e., rendered using a component that renders nothing). Then it's up to you how this logic looks like and whether it's a part of the schema, bridge, or even some external logic.

Having said that, there's also Form Builder - our WYSIWYG builder based on uniforms. It has a graphical editor of boolean expressions that determine whether a field should be rendered or no. It's a paid product, but maybe it's interesting for you too. In this case, feel free to contact us there or me directly.

@pharreX19
Copy link
Author

Hey @radekmie, Thanks for the reply.
Im currently using the Form Builder that you have referred to and the displayIf component is doing pretty well when applied to a "LayoutNodeKind.Field". However I couldn't figure out a way to apply the condition (display the container when a certain condition is met) to a "LayoutNodeKind.Container".

Im hoping that when a condition is applied to a "Container (LayoutNodeKind.Container)", then the whole container with its children could be displayed/ hidden based on that condition.

@radekmie
Copy link
Contributor

Ah, got it. Containers don't support conditional rendering yet, but we have it on our list. I'll forward your request to the team.

@radekmie radekmie transferred this issue from vazco/uniforms Jan 5, 2023
@radekmie radekmie removed their assignment Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants