F
Filament13mo ago
Eth

showing external options

Once the user enter the place id i want the name, price and options to be filled I did the name and price part but I couldn’t figure it out with option (it’s a part of json array coming from a repeater called “options” containing option (what i want) and price)
No description
11 Replies
Dennis Koch
Dennis Koch13mo ago
So you want to change the options not the value? Then you need to do that via the options method. Use a closure and load them inside the closure. You can use $get there too
Eth
EthOP13mo ago
Nope, no changes i want the user to be able of seeing the options
Dennis Koch
Dennis Koch13mo ago
Well, what did you do? Share your code
Eth
EthOP13mo ago
Same code above, after entering the id the user should be able to see the options (name) from options in Place class and select
Dennis Koch
Dennis Koch13mo ago
Um, so why didn't you try what I recommended?
->options(function ($get) {
... get your options ...
})
->options(function ($get) {
... get your options ...
})
Eth
EthOP13mo ago
I did but it’s showing “Call to a member function options() on array” ( i want to get only option name from the options array to select )
No description
Lara Zeus
Lara Zeus13mo ago
it is always better to copy the code and add it here with the correct formatting ofc so we can copy and paste code and tell you what to do I don't want to write your code again 🙂 it's too long and I am lazy 🤷‍♂️ anyway your options is array so do ['options'] instead of ->options
Eth
EthOP13mo ago
Forms\Components\TextInput::make('placeID')
->label('Place ID')
->required()
->maxLength(50)
->live()
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeID');
$placeName = Place::find($place)->placeName;
$placePrice = Place::find($place)->placePrice;
$options = Place::find($place)->options;
$option = $options->options($state['option']);
$set('placeName', $placeName);
$set('totalPrice', $placePrice);
$set('options', $options);
}),
Forms\Components\TextInput::make('placeName')
->label('Place Name')
->disabled()
->dehydrated(false),
Forms\Components\Select::make('options')
->label('Options'),’m
Forms\Components\TextInput::make('placeID')
->label('Place ID')
->required()
->maxLength(50)
->live()
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeID');
$placeName = Place::find($place)->placeName;
$placePrice = Place::find($place)->placePrice;
$options = Place::find($place)->options;
$option = $options->options($state['option']);
$set('placeName', $placeName);
$set('totalPrice', $placePrice);
$set('options', $options);
}),
Forms\Components\TextInput::make('placeName')
->label('Place Name')
->disabled()
->dehydrated(false),
Forms\Components\Select::make('options')
->label('Options'),’m
Lara Zeus
Lara Zeus13mo ago
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeID');
$placeName = Place::find($place)->placeName;
$placePrice = Place::find($place)->placePrice;
$options = Place::find($place)->options;
$option = $options[$state['option']];
$set('placeName', $placeName);
$set('totalPrice', $placePrice);
$set('options', $option);
})
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeID');
$placeName = Place::find($place)->placeName;
$placePrice = Place::find($place)->placePrice;
$options = Place::find($place)->options;
$option = $options[$state['option']];
$set('placeName', $placeName);
$set('totalPrice', $placePrice);
$set('options', $option);
})
try this one, but I hope you understand the changes I made and why 🙂 also I hope it will work
Dennis Koch
Dennis Koch13mo ago
You should add this to the select. Not to a random array that doesn’t have that method. And remove your $set('options' logic from afterStateUpdated
Eth
EthOP13mo ago
“Cannot access offset of type string on string”
Want results from more Discord servers?
Add your server