Skip to content

Commit

Permalink
disabledFields
Browse files Browse the repository at this point in the history
  • Loading branch information
KamranBiglari committed Sep 25, 2024
1 parent 0abcd73 commit cb820ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/FilamentEditProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class FilamentEditProfilePlugin implements Plugin

protected array $registeredCustomProfileComponents = [];

protected array $disabledFields = [];

public function getId(): string
{
return 'filament-edit-profile';
Expand Down Expand Up @@ -350,4 +352,16 @@ public function getRegisteredCustomProfileComponents(): array
->sortBy(fn (string $component) => $component::getSort())
->all();
}

public function disableFields(array $fields): self
{
$this->disabledFields = array_merge($this->disabledFields, $fields);

return $this;
}

public function getDisabledFields(): array
{
return $this->disabledFields;
}
}
6 changes: 4 additions & 2 deletions src/Livewire/EditProfileForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public function form(Form $form): Form
->hidden(! filament('filament-edit-profile')->getShouldShowAvatarForm()),
TextInput::make('name')
->label(__('filament-edit-profile::default.name'))
->required(),
->required()
->disabled(in_array('name', filament('filament-edit-profile')->getDisabledFields())),
TextInput::make('email')
->label(__('filament-edit-profile::default.email'))
->email()
->required()
->unique($this->userClass, ignorable: $this->user),
->unique($this->userClass, ignorable: $this->user)
->disabled(in_array('email', filament('filament-edit-profile')->getDisabledFields())),
]),
])
->statePath('data');
Expand Down

0 comments on commit cb820ed

Please sign in to comment.