Programmatically change the values of a single Livewire component form action

Context I'm working from a custom Livewire component. What I'm looking for My users can create 1 or more clickable text elements on the page. When they click one, the form should show with one of the fields set to the value of the element they clicked. Initial progress I have a form action that templates the fields needed with initial defaults. I can mount this in my click event and have reference to what was clicked. Current problem I'm not sure how to programmatically change the value of certain form fields, and have this shown the next time the action is mounted? Example
#[On('element-clicked')]
public function onElementClicked(string $clickedElementText)
{
// I'm looking to update the 'input' field with the value of $clickedElementText
}

public function editAction(): Action
{
return Action::make('edit')
->fillForm([
'input' => 'Initial'
])
->form([
TextInput::make('input')
])
->action(function (array $data) {

});
}
#[On('element-clicked')]
public function onElementClicked(string $clickedElementText)
{
// I'm looking to update the 'input' field with the value of $clickedElementText
}

public function editAction(): Action
{
return Action::make('edit')
->fillForm([
'input' => 'Initial'
])
->form([
TextInput::make('input')
])
->action(function (array $data) {

});
}
2 Replies
milkslices
milkslicesOP6mo ago
I've added an example to make what I'm trying to do clearer as the form is defined on the action itself and shown within the modal that opens Turns out the answer was relatively simple:
#[On('element-clicked')]
public function onElementClicked(string $clickedElementText)
{
$this->editAction->fillForm([
'input' => $clickedElementText
]);
}
#[On('element-clicked')]
public function onElementClicked(string $clickedElementText)
{
$this->editAction->fillForm([
'input' => $clickedElementText
]);
}
Want results from more Discord servers?
Add your server