Select::make() get the inner html
$state and $old get the
value=""
like 1,2,3 etc
but how do I get the value the user sees like <option value="1"> how_do_i_get_this </option>
Solution:Jump to solution
would you like to get the label?
```php
->afterStateUpdated(function (?string $state, Set $set, Select $component) {
$set('code-editor', $component->getOptionLabel());...
21 Replies
You can't get the label. That's not how HTML forms work.
so I need to do an eloquent query and get the label from the db?
Yes.
can I preload this data somehow?
if I query everytime afterStateUpdated(), that might be a lot
When do you want to preload it? Where else are you using that data?
it's a list of
languages
for programming languages,
there is a Markdown
editor on the page
I want to insert the newly selected language into the editor
in this editor, adding '''javascript
will change the code formatting to javascript, etcDo you even need the value then? What do you use
slug
for?the
slug
is the <option value="id"> slug </option>
that the user seesI mean: Do you need both? Otherwise just change what you use as value
you can change the value filament uses?
Btw. you shouldn't use
->relationship()
if you don't want to save it to a relationship
Just use ->options([])
oh yes it is a relationship
$code->language->slug
it's got a pivot table
the Select::make works perfectly out of the box
pretty amazing
So you want to insert this into the editor but also save it to the DB?

see the
'''php
when the user changes the language with the Select
I want to replace that '''php
with '''new language
to trigger the code highlightingYeah, I don't think there is an easier way then load it from DB and replace it
so can I query the db just once and store the data somewhere?
I tried to do this on the resource, but it didn't work
if not, I will have to query every time the user changes the Select
Solution
would you like to get the label?
?
let me try this code
@Filament legendary, it worked
oops
@Leandro Ferreira legendary
Good to know
@Dennis Koch thanks for your help
I'm just loving this filament