native(false) won't work on depended dropdown, any idea?
->filters([
SelectFilter::make('school_class_and_section')
->form([
Select::make('school_class_id')
->label('Class')
->relationship('school_classes', 'name')
->native(false)
->live(),
Select::make('section_id')
->label('Section')
// ->native(false) NOTE: Not loading the dropdown unless native is true because sections dropdown depends on classes
->placeholder(fn (Get $get): string => empty($get('school_class_id')) ? 'First select a class' : 'Select an option') ->relationship( 'sections', 'name', fn (Builder $query, Get $get) => $query ->where('sections.school_class_id', $get('school_class_id')) ), ]) Select::make('section_id') won't load if native() is set to false. I think because of arrow fn. The Remove item feature in native(false) is very important in this regard. Any idea how to go around this?
->placeholder(fn (Get $get): string => empty($get('school_class_id')) ? 'First select a class' : 'Select an option') ->relationship( 'sections', 'name', fn (Builder $query, Get $get) => $query ->where('sections.school_class_id', $get('school_class_id')) ), ]) Select::make('section_id') won't load if native() is set to false. I think because of arrow fn. The Remove item feature in native(false) is very important in this regard. Any idea how to go around this?
15 Replies
any idea still?
Unfortunately,
PlaceHolder
will only be calculated and initialized once in every (not native) select. As the component is wire:ignored
.
It would need a bit of restructuring for the following code to support your case.
I think you can use the hint label as an alternative.Thanks for this input. However, using hint does same as placeholder in the sense that it doesn't remove the 'section' item if you want to once you've already select one. If you decide to unselect the 'section' it just change the query to null and filters no result. I want to be able to remove a 'section' item even after one item is selected, just like you can remove (X) a 'class' item. I hope you get my point
I believe the query of the section are dependent on the class, right
Are you saying you want to clear the section once the class changes?
and I meant you could still use the (not native select), with the hint or helper, you are only notifying the user to select a class first for the options of the section to show. I'm I right?
I simply want to be able to remove section item just like you can remove a class item by pressing 'X' on class select option. Kindly check the attachment you sent
That's why I said to use (hint/helper) instead of placeholder with (native(false)) . if it matches your need
native(false) won't work as long as I use Get $get closure.
Use your code like this
for some reason, native(false) refuses to load option once there's a $get closure.
CAn you try it from your end?
Let me try and create a schema for this
Alright
I believe there is something wrong with the relationship
use the following
instead of relationship
Oh nice one. it indeed loaded the option with native(off). Only issue is that placeholder condition didn't work but using hint worked. This is still better and useable. I believe it has to do with $get utility. the relationship in the first Select do work fine without issues.