aster255
aster255
FFilament
Created by aster255 on 2/11/2025 in #❓┊help
Adding a form to a Livewire component
okay i was able to solve it. my thesis partner was using
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
in app.blade.php causing the "message" to not bind when using textarea when submitting.
10 replies
FFilament
Created by aster255 on 2/11/2025 in #❓┊help
Adding a form to a Livewire component
My file after reading 5x, the documentation above, anxious if its a skill issue on my part 😅 😅 if i change Forms\Components\Textarea::make('message') ->required() ->columnSpanFull(), to Forms\Components\TextInput::make('message') ->required() ->maxLength(100), i am able to submit and save...
10 replies
FFilament
Created by aster255 on 2/11/2025 in #❓┊help
Adding a form to a Livewire component
<?php

namespace App\Livewire;

use App\Models\ContactMessages;
use Filament\Forms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;
use Illuminate\Contracts\View\View;

class CreateCm 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([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('last_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->maxLength(20)
->default(null),
Forms\Components\Textarea::make('message')
->required()
->columnSpanFull(),
Forms\Components\TextInput::make('ip_address')
->maxLength(45)
->default(null),
])
->statePath('data')
->model(ContactMessages::class);
}

public function create(): void
{
$data = $this->form->getState();

$record = ContactMessages::create($data);

$this->form->model($record)->saveRelationships();
}

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

namespace App\Livewire;

use App\Models\ContactMessages;
use Filament\Forms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;
use Illuminate\Contracts\View\View;

class CreateCm 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([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('last_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->maxLength(20)
->default(null),
Forms\Components\Textarea::make('message')
->required()
->columnSpanFull(),
Forms\Components\TextInput::make('ip_address')
->maxLength(45)
->default(null),
])
->statePath('data')
->model(ContactMessages::class);
}

public function create(): void
{
$data = $this->form->getState();

$record = ContactMessages::create($data);

$this->form->model($record)->saveRelationships();
}

public function render(): View
{
return view('livewire.create-cm');
}
}
10 replies