F
Filamentβ€’2y ago
Daniel

Fill form data via emitted action

Is it possible to fill form data via an emitted action? I do have an action:
Action::make('apply')
->action(function ($record) {
$this->emit('applySelection', $record);
}),
Action::make('apply')
->action(function ($record) {
$this->emit('applySelection', $record);
}),
which should do the following:
public function applySelection($record): void
{
$formData = $this->form->getState();
$this->form->fill($record);
}
public function applySelection($record): void
{
$formData = $this->form->getState();
$this->form->fill($record);
}
but it seems like the form always get submitted instead of filling in the data in the corresponding fields.
5 Replies
Daniel
DanielOPβ€’2y ago
Filling via emitting seems to work only if I fill the form initially (when mounting) with the expected (empty) fields.
Dan Harrin
Dan Harrinβ€’2y ago
why would you emit you can do that within the action() function
Daniel
DanielOPβ€’2y ago
I want to fill in a chosen repeater item via modal (in which i have a table listing all available models) each repeater item has a button which opens the modal for model selection and after hitting "apply" in the modal the selected model is passed to the form and should fill the specific repeater item it is done via 2 components: form component and modal component
Daniel
DanielOPβ€’2y ago
Daniel
DanielOPβ€’2y ago
due to the documentation it seems like $this->form->getState();validates all the fields (which are empty of course). is there another way to get the form data without validation (at this point)? $formData = $this->form->getRawState(); did it πŸ™‚
Want results from more Discord servers?
Add your server