Dynamic `required()`/`visible()` within a Repeater
I've got a
Form
with Select
:
The Event
model has certain attributes which inform the requirements of the form, e.g. $event->is_food_provided
.
Within a Fieldset
, updating the visibility of a TextInput
works:
However, this does not seem to work when it's inside a Repeater
:
For the Repeater
, the visible()
check gets executed and is respected on page load, but not when the Select
/Event
is changed.
Is this expected behavior, am I doing something wrong, or is this a bug? I couldn't find anything in the documentation or GitHub issues about this.7 Replies
This is because event_id isn't there. what you want is to traverse out of the repeater.
I think maybe ../ or ../../../
But you just need to to traverse to the right path of where event_id is.
@toeknee That worked! Thank you so much. I didn't know about this traversal stuff. Very cool.
Follow-up question if you don't mind: There are actually a number of fields that rely on this
Event
, so I'm calling Event::find($get(...))
multiple times per update. Is there a way to reuse the model that's loaded within the Select
to prevent these duplicate queries?@grardb
That's a tricky one.. is thise for the fields within the repeater atleast?
Some of them - the others are outside the
Repeater
😅
It's ultimately not the end of the world (a few extra queries for an admin panel). I just always like to keep DB queries to a minimum.Yeah I hear you, I would write a function on the class, which caches the query if the ID is the same
the you can do:
on save(after function) you could also then do:
Oh, interesting idea!
Thanks so much for your help 😁
More than welcome!