Select dynamic placeholders
Hello everyone, I'm currently trying to make a select placeholder dynamic.
In this code I was hoping the placeholder to change if the $intervention is set to null or not. But no, it stays at the first thing it was built with. Good to know, This field is updated when I update a date field in the same form. And the disable works well, just the placeholder stays the same.
Is it possible or am I having a seizure ?
10 Replies
That should work right?
I think placeholders only work on create pages if im not mistaken.
Well it works but like mine, that's to say, it sets the placeholder when the field is created (my select is inside a TableRepeater) but I want it to be disabled under certain circonstances (this works, it's disable when the other form field $get('is_occupied') is true or false), and I want the placeholder to change too, I need placeholder X when $get('intervention') is false and placeholder Y when it's true. without reloading the page, I need live updates.
Doesn't the example i gave do that? Only thing you have to do is add some condition.
Aaah you mean duplicate the select, ok I did not understood that way ! Yes I think it works, I will try, but we can't dynamically change the place holder ?
No not duplicate, just set placeholder based on some field condition.
Well in Select::make('examples') the placeholder must be either an hard coded string or the intervention value. When I try
It does the same thing than mine, it put intervention value in placeholder when needed, good, but in cases where it has to be the hard coded string (when $get('intervention') === null) the value of the placeholder does not change.
Did you make the correct field
live
?Yes both of my fields are live. Sorry for the waiting between my responses, meetings don't want to end.
I was wondering if the only option is to add a Placeholder field and set its visibility and the visibility of my Select according to my conditions.
Here the field which triggers 'blabla' Select changes
You dont have to set a placeholder (or can), you just have to listen to another field on that specific field. Maybe i dont understand your problem or perhaps the problem you are running into is because of a repeater? In that case you need to use
../
to go to the main form (see docs)I thought about ../ but If I dump $get('intervention') inside my placeholder I get something logical, like null or a string (I want to put this string for the placeholder, or an hard coded string if $get('intervention') is null)
(Thank you for taking time trying to resolve this, and sorry if I am not able to make myself clear)
I have a really good example. (something that tells me that placeholders cannot be live) I fill up my form, my Selects with the placeholders (which are in a table repeater) are not set because my tableReapeater is not visible.
When I set the start_date the tableRepeater appears because visible condition is met, at this moment I build my Selects, if I set a date where I expect my $get('intervention') to be set to "My super placeholder" the placeholder will be set, as expected, to My super placeholder". If I close my form and open it again, but this time I choose a date where I expect $get('intervention') to be null, as expected again, the placeholder is set to my hard coded string. So everything works !
But If I change date without closing my form, placeholders don't change.
My solution for now (tested) is to make two field, one select, one TextInput (or whatever) and control visibility