Skip to content

Commit

Permalink
Merge pull request #368 from cgsmith/patch-1
Browse files Browse the repository at this point in the history
Add better example for custom component
  • Loading branch information
jeffgreco13 authored Jun 9, 2024
2 parents ef4c791 + 197e028 commit dd43039
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,40 @@ use Filament\Forms\Form;
class MyCustomComponent extends MyProfileComponent
{
protected string $view = "livewire.my-custom-component";
public array $only = ['my_custom_field'];
public array $data;
public $user;
public $userClass;

//
// this example shows an additional field we want to capture and save on the user
public function mount()
{
$this->user = Filament::getCurrentPanel()->auth()->user();
$this->userClass = get_class($this->user);

public array $data;
$this->form->fill($this->user->only($this->only));
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
TextInput::make('my_custom_field')
->required()
])
->statePath('data');
}

// only capture the custome component field
public function submit(): void
{
$data = collect($this->form->getState())->only($this->only)->all();
$this->user->update($data);
Notification::make()
->success()
->title(__('Custom component updated successfully'))
->send();
}
}

```
Expand Down

0 comments on commit dd43039

Please sign in to comment.