F
Filament17mo ago
Stevee

how to fill form at simple page

tried to use $this->form->fill([]) but cant fill the form
21 Replies
Vp
Vp17mo ago
Post your code
Stevee
SteveeOP17mo ago
cant share my full code, but the main idea is something like
class GuestPage extends SimplePage
{

public function mount(): void
{
$this->form->fill([ $formContent ]);
}

public function form(Form $form): Form
{
return $form;
}
}
class GuestPage extends SimplePage
{

public function mount(): void
{
$this->form->fill([ $formContent ]);
}

public function form(Form $form): Form
{
return $form;
}
}
tried this with extends CreateRecord the form fill can work by using this
protected function fillForm(): void
{
$this->form->fill([ $formContent ]);
}
protected function fillForm(): void
{
$this->form->fill([ $formContent ]);
}
but I need to use simplepage because the form need to be for guest(non login user)
LancelotGamer
LancelotGamer17mo ago
what is $formContent? If it is array this not going to work It is an array inside an array
Stevee
SteveeOP17mo ago
oh wrong copy paste, it's should be like
$this->form->fill([
'fieldName' => 'fieldValue',
])
$this->form->fill([
'fieldName' => 'fieldValue',
])
Vp
Vp17mo ago
Check this, it should work https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-form
public function mount(): void
{
$this->form->fill([
'title' => 'value'
]);
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->required(),
])
}
public function mount(): void
{
$this->form->fill([
'title' => 'value'
]);
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->required(),
])
}
Stevee
SteveeOP17mo ago
ah found out the problem, need to declare the fields variable thought no need anymore in v3
ValentinC
ValentinC16mo ago
Can you please explain how you solved the issue?
Stevee
SteveeOP16mo ago
at my case, I need to declare the field variable ex.
public ?string $name = null;
public ?string $name = null;
for TextInput::make('name')
ValentinC
ValentinC16mo ago
I am struggling with this for the last 3 days. Here is my code : <?php namespace App\Livewire; use Carbon\Carbon; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Forms\Form; use Illuminate\Support\Str; use Livewire\Component; class RegisterUserAndCarForm extends Component implements HasForms { use InteractsWithForms; public ?array $data = []; public ?string $title = null; public function mount(): void { $this->form->fill([ 'title' => 'text', ]); } public function form(Form $form): Form { return $form ->schema([ TextInput::make('title') ->required(), ]) ->statePath('data'); } public function render() { return view('livewire.register-user-and-car-form'); } } @Stevee do you see anything strange here?
Stevee
SteveeOP16mo ago
cant find anything strange
Vp
Vp16mo ago
Remove ->statePath('data') this and try again..
ValentinC
ValentinC16mo ago
This did not helped. Here is the blade file also. <div> <form wire:submit="create"> {{ $this->form }} <button type="submit"> Submit </button> </form> <x-filament-actions::modals /> </div> @Vp @Stevee if you run the code .. does it work for you?
LeandroFerreira
LeandroFerreira16mo ago
Are you using the Form Builder outside the admin panel?
ValentinC
ValentinC16mo ago
Yes. I use it in a Livewire component @Leandro Ferreira
Vp
Vp16mo ago
Working fine
Vp
Vp16mo ago
My code
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;

public ?string $title = null;

public function mount(): void
{
$this->form->fill([
'title' => 'text new data',
]);
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->required(),
]);
}

// blade.php
{{ $this->form }}
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;

public ?string $title = null;

public function mount(): void
{
$this->form->fill([
'title' => 'text new data',
]);
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->required(),
]);
}

// blade.php
{{ $this->form }}
ValentinC
ValentinC16mo ago
do you have components/layouts/app.blade file? mine has this content: <!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>{{ $title ?? 'Page Title' }}</title> @vite(['resources/css/app.scss', 'resources/js/app.js']) </head> <body> {{ $slot }} @livewireScriptConfig </body> </html> I wonder if the issue is connected to an older version of the JS files
Vp
Vp16mo ago
No i dont have layouts for livewire, i just include it on my sidebar.. i'll try to check on full livewire if you still have this error on 2moro, rn i am out of work dnt have computer
awcodes
awcodes16mo ago
You’re missing the filament styles and scripts directives in your layout. https://filamentphp.com/docs/3.x/forms/installation#configuring-your-layout
ValentinC
ValentinC16mo ago
Yes. You are right. Thank you! How can i include the CSS for the grid system in this custom layout?
awcodes
awcodes16mo ago
Use the grid blade component.

Did you find this page helpful?