Transfer data from form to Action Form

Hey Everyone, On my website there's a file input that on change has to activate a modal action with additional fields. In that action there's also a file input field. I want to be able to transfer the inputted files in the form to the ones in the action. I have of course tried the fillForm() method, but that function seems to run on loading the page and not on calling the action, so the data to transfer doesn't exist yet. There's probably a event to be called, but I haven't been able to figure it out yet and the documentation doesn't tell to much about this. The file input in fillForm() expects data be like this: [ '<possible_directory>/<filename>.<format>', ]. The data you get from the form is exactly that. So that should work. I hope someone can help with this.
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\FileUpload::make('files')
->multiple()->reactive()->directory(Auth::id())
->preserveFilenames()
->afterStateUpdated(function () {
$this->mountAction('sendMessage');
})
->label(''),
])
->statePath('data');
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\FileUpload::make('files')
->multiple()->reactive()->directory(Auth::id())
->preserveFilenames()
->afterStateUpdated(function () {
$this->mountAction('sendMessage');
})
->label(''),
])
->statePath('data');
}
public function sendMessageAction(): Action
{
return Action::make('sendMessage')
->label('Verstuur bericht')
->fillForm(['files' => $this->form->getState()['files']])
->form([
Forms\Components\TextInput::make('subject')
->label('Naam document')
->required(),
Forms\Components\FileUpload::make('files')
->multiple()
->previewable()
->preserveFilenames()
->directory('livewire-tmp')
->label('Bestanden')
])
->action(function (array $data) {
app(SaveSentMessage::class)($data);
});
}
public function sendMessageAction(): Action
{
return Action::make('sendMessage')
->label('Verstuur bericht')
->fillForm(['files' => $this->form->getState()['files']])
->form([
Forms\Components\TextInput::make('subject')
->label('Naam document')
->required(),
Forms\Components\FileUpload::make('files')
->multiple()
->previewable()
->preserveFilenames()
->directory('livewire-tmp')
->label('Bestanden')
])
->action(function (array $data) {
app(SaveSentMessage::class)($data);
});
}
0 Replies
No replies yetBe the first to reply to this messageJoin