Can you access the search state in a create action?

Sorry if the title doesn't make much sense I have a select like this
Select::make('user_id')
->createOptionAction(
fn (Action $action) => $action
->modalWidth('3xl'),
)
->createOptionForm(fn(Select $component) => [
TextInput::make('name')
->default(fn () => $component->getState())
->required(),
])
->createOptionUsing(fn ($state, $data) => dd($state, $data))
->live()
Select::make('user_id')
->createOptionAction(
fn (Action $action) => $action
->modalWidth('3xl'),
)
->createOptionForm(fn(Select $component) => [
TextInput::make('name')
->default(fn () => $component->getState())
->required(),
])
->createOptionUsing(fn ($state, $data) => dd($state, $data))
->live()
Is there a way to access what the user has typed in the select to be used as a default value in the createOptionForm? $component->getState() is null
8 Replies
toeknee
toeknee4w ago
Did you try passing $state in to th eaction?
ChesterS
ChesterSOP4w ago
Sorry, what do you mean? I need the state in the form, not the action 🤔 There's some weird interactions with the
->createOptionAction(
fn (Action $action) => $action
->modalWidth('3xl'),
)
->createOptionAction(
fn (Action $action) => $action
->modalWidth('3xl'),
)
it can affect the state of the fom, but I'm having trouble getting the actual state of the select hmm Hmm now that I think about it, getState() is wrong since this is the search, not the value of the select 🤔
toeknee
toeknee4w ago
->createOptionAction(
fn (Action $action, $state) => $action
->modalWidth('3xl'),
)
->createOptionAction(
fn (Action $action, $state) => $action
->modalWidth('3xl'),
)
Might not work... haven't checked the code.
ChesterS
ChesterSOP4w ago
Sorry, I wasn't clear in the original question - what I want to do is pre-fill the form with the text they're trying to search for. So let's say they are searching for someone named John and they want to create one, the createOptionForm would look something like this
->createOptionForm(fn(Select $component) => [
TextInput::make('name')
->default(fn () => 'John')
->required(),
])
->createOptionForm(fn(Select $component) => [
TextInput::make('name')
->default(fn () => 'John')
->required(),
])
which I don't think is possible. Oh well, maybe some filament wizard has an idea oh how to access the search value
toeknee
toeknee4w ago
->createOptionAction(
fn (Action $action, $state) => $action
->modalWidth('3xl')
->fillForm([‘name’ => $state])
)
->createOptionAction(
fn (Action $action, $state) => $action
->modalWidth('3xl')
->fillForm([‘name’ => $state])
)
Might not work... haven't checked the code or if state works on the option form closure
ChesterS
ChesterSOP4w ago
Nope, doesn't work either 😦 I don't think 'state' is what I want in the first place since the search is not considered the state - it's something else that is not accessible at some point
toeknee
toeknee4w ago
well the state should be the value of the input. Just access it via the livewire element?
ChesterS
ChesterSOP4w ago
Hmm I can't seem to find it :/ Not sure if the search is not passed down or if there's some DOM magic I can do to get it 🤔
Want results from more Discord servers?
Add your server