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

Question on showIf #221

Closed
otrsw opened this issue Jun 11, 2022 · 5 comments
Closed

Question on showIf #221

otrsw opened this issue Jun 11, 2022 · 5 comments

Comments

@otrsw
Copy link

otrsw commented Jun 11, 2022

This is not an issue - just a question around usage of the showIf() method on the Tabs class.
The typical use case for me would be that the truthy/falsy value would depend on "other" fields on the form, and not data that is available on the "back end" yet.

Typically other components or Nova features (like dependsOn) would take a statement that is evaluated against these fields. so you could pass a statement that should evaluate to true or false using the fieldnames on the same resource.

Some pseudo code to illustrate:

Toggle::make('Show tab','show_tab'),
new Tabs('Example', [
Tab::make('ShowHide',[ ..//fields in tab ])->showIf('show_tab' == true)
]):

The expected behavior is that as the user completes the form, certain tabs are hidden or shown, before any data is sent back to the backend in update or create call...

I'm pretty sure I am missing something, because the fact that there is a showIf and showUnless function suggests that the above should be possible, otherwise I would simply use back-end logic to add / not add the Tab to the Tabs object?

So could you please clarify with an example of a closure or statement in the correct syntax in order to use the "front end" field values?

PS: This example obviously only pertains to TabsOnEdit - on athe detail view I have the latest persisted values of the underlying model and can use the showIf using those attribues. But during edit, I would expect to have access to the fields on the form

Hope it makes sense...
PS: Awesome component BTW!!!

@marcfil
Copy link
Collaborator

marcfil commented Jun 14, 2022

The showIf and showUnless features were already in there when I took over. They're fully backend based, never really understood why anyone would use it like that either.

I'm open to ideas on how to make your wish possible, personally I think it would be hard to figure out how to keep it simple, as the idea is that tabs can be used in both detail and form views.

@philipbaginski
Copy link

The showIf and showUnless features were already in there when I took over. They're fully backend based, never really understood why anyone would use it like that either.

I'm open to ideas on how to make your wish possible, personally I think it would be hard to figure out how to keep it simple, as the idea is that tabs can be used in both detail and form views.

Hi!

I will show you simple case:

In the resource Runner I have tab: Workouts with workouts belongsTo runner. Runner can be active or inactive. If I'm creating workout for runner, on the list I can see only active runners. If I go to inactive detail page runner I can still see tab Workout, but there is no need to create workout.

So, if there is any condition/s we don't want to some tab, we can hide/show it.

I think it's really usefull.

@marcfil
Copy link
Collaborator

marcfil commented Jun 19, 2022

But from the example you gave, those are server side conditions?

@philipbaginski
Copy link

The same as for Nova fields.

@RVxLab
Copy link
Collaborator

RVxLab commented Jun 27, 2022

I originally added showIf and showUnless as requested in #58 and #129. They were meant for more simple checks like user permissions, whether a model exists, or if an existing model has a certain relationship.

However in your example I would just a policy.

@marcfil marcfil closed this as completed Sep 8, 2022
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

4 participants