Adding Submit-Button via getFormSchema

Hey - Maybe I am too tired, but right now I struggle on creating a simple form on a Page. So far I got this:
protected function getFormSchema() : array
{
return [
Section::make('Search somethine')->schema([
TextInput::make('parameter_one')->label('Parameter one'),
TextInput::make('parameter_two')->label('Parameter two'),
])
];
}
protected function getFormSchema() : array
{
return [
Section::make('Search somethine')->schema([
TextInput::make('parameter_one')->label('Parameter one'),
TextInput::make('parameter_two')->label('Parameter two'),
])
];
}
What I want is to create a simple search-form with 2 parameters where there is a button below the Text-Inputs which then submits the form, but as soon as I try to add Action::make() PHP comes down on me. I am sure I can do what I want somehow within the getFormSchema()-method, but I don't see how. I want the button specificly below the Textinputs and NOT on the top right where the Page-Actions would normally reside. What am I missing here? (@pboivin)
8 Replies
Husky110
Husky110OP2y ago
Yes and no. It was made via php artisan make:filament-page which already includes the Forms-Interface and -Trait. So again this more about "how the flying f do it get this inside the schema?"
LeandroFerreira
did you add in the view file?
<form wire:submit.prevent="submit">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>
<form wire:submit.prevent="submit">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>
Husky110
Husky110OP2y ago
Yep - I did, but that has two sideeffects: 1.) It places the button outside the Section... 2.) When I click on the button - i get the following error: Unable to set component data. Public property [$parameter_one] not found on component. My Page-Class looks like this:
<?php

namespace App\Filament\Pages\Tools\Batchtracing;

use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Actions\Action;
use Filament\Pages\Page;
use Filament\Resources\Form;

class GetRequestedBatchInfo extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static ?string $navigationLabel = 'MEEPER';

public $paramater_one;
public $parameter_two;

protected static function getNavigationLabel(): string
{
return 'MEEPER';
}

protected static string $view = 'components.my-pages.tools.get-requested-batch-info';

protected function getFormSchema() : array
{
return [
Section::make('Search something')->schema([
TextInput::make('parameter_one')->label('Parameter one'),
TextInput::make('parameter_two')->label('Parameter two'),
])
];
}


public function submit()
{
dd($this->form->getState());
}



}
<?php

namespace App\Filament\Pages\Tools\Batchtracing;

use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Actions\Action;
use Filament\Pages\Page;
use Filament\Resources\Form;

class GetRequestedBatchInfo extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static ?string $navigationLabel = 'MEEPER';

public $paramater_one;
public $parameter_two;

protected static function getNavigationLabel(): string
{
return 'MEEPER';
}

protected static string $view = 'components.my-pages.tools.get-requested-batch-info';

protected function getFormSchema() : array
{
return [
Section::make('Search something')->schema([
TextInput::make('parameter_one')->label('Parameter one'),
TextInput::make('parameter_two')->label('Parameter two'),
])
];
}


public function submit()
{
dd($this->form->getState());
}



}
LeandroFerreira
public function mount(): void
{
$this->form->fill();
}
public function mount(): void
{
$this->form->fill();
}
Husky110
Husky110OP2y ago
Great! That fixes the error - but on the button -> guess I will have to make another view... right? And yes - I promise not to code anymore today... (We got a saying here: What comes after beeing tired? Beeing stupid. And I am post-tired as hell... 😄 )
LeandroFerreira
If you want to add the submit button inside the Section, you can use ViewField:
ViewField::make('submit')->view('submit')
ViewField::make('submit')->view('submit')
<x-filament::button
type="submit"
wire:target="submit">
Submit
</x-filament::button>
<x-filament::button
type="submit"
wire:target="submit">
Submit
</x-filament::button>
Husky110
Husky110OP2y ago
Thank you!
Want results from more Discord servers?
Add your server