Beginner form question - Field value is 'null'

Here is my form code:
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('subject')->maxLength(255)->required(),
Textarea::make('message')->minLength(10)->maxLength(50000),
])
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('subject')->maxLength(255)->required(),
Textarea::make('message')->minLength(10)->maxLength(50000),
])
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
When I input values in both fields and hit Submit, the dd() output is correct for 'subject' but shows 'null' for the 'message' field. Any ideas on why this is happening?
9 Replies
LeandroFerreira
did you add $this->form->fill() in the mount method? Could you share the whole code?
heat23.
heat23.4w ago
@Leandro Ferreira
<?php

namespace App\Livewire;

use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class CreatePost extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

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

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('subject')->maxLength(255)->required(),
Textarea::make('message')->minLength(2)->maxLength(50000),
])
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}

public function render(): View
{
return view('livewire.create-post');
}
}
<?php

namespace App\Livewire;

use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class CreatePost extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

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

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('subject')->maxLength(255)->required(),
Textarea::make('message')->minLength(2)->maxLength(50000),
])
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}

public function render(): View
{
return view('livewire.create-post');
}
}
LeandroFerreira
console errors?
heat23.
heat23.4w ago
@Leandro Ferreira I have "Detected multiple instances of apline running" and 500 Internal server error to /livewire/update
LeandroFerreira
check the log
heat23.
heat23.4w ago
Weird that the "message" field (textarea) does not appear in the payload:
No description
heat23.
heat23.4w ago
I am tailing the laravel.log, but nothing comes up
heat23.
heat23.4w ago
I commented out {{-- @vite('resources/js/app.js') --}} and I am getting a non-null value in the Textarea field, but still getting the 500 error in console My vite.config.js looks like this:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: [
'app/Livewire/**',
],
}),
],
});
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: [
'app/Livewire/**',
],
}),
],
});
Want results from more Discord servers?
Add your server
More Posts