F
Filament4mo ago
slamx_

Re-Render Form Schema

How can I use a variable that is set in the Emit function in the form schema? The form is in a modal and when the modal is opened, a fill method is used to set the data (edit form). Depending on the authorization for the record, certain fields should now be set to disabled. Does anyone have a solution? Is it possible to re-render the schema with custom parameters?
8 Replies
toeknee
toeknee4mo ago
Are you not using ->fillForm() ? then have the fields live
slamx_
slamx_4mo ago
Sure but how I can set a ->disabled(false) inside a fill for example? I need to change the disabled based on the auth (like describe)
toeknee
toeknee4mo ago
how are you determining authorisation? disabled(fn($record) => !$record->canEdit))
slamx_
slamx_4mo ago
Its a edit form outside the admin panel - its a form to use to edit a model which can have multiple users as value. It must be checked whether there are several users in a model field; if so, only users with the corresponding authorization can edit the users - otherwise it needs to be disabled the Fill is setting up inside a emit function. Inside the emit the record id is defined
toeknee
toeknee4mo ago
Once you mount it becomes a record. Or simply add the standard Laravel policy? Then the policy checks the record prior to consenting
slamx_
slamx_4mo ago
Did you read my problem? ^^
toeknee
toeknee4mo ago
I am reading it, but without code can't fully understand your issue. using a form inside or outside the admin panel would mean the model can a policy as per standard laravel policies. You can add a custom policy rule and do a user check passing the model into it.
slamx_
slamx_4mo ago
Ok other question - is it possible to reload the form schema after the fill? Or to update a form component via function? Like to setup a ->disabled() afterwards? When I have a component like this: Select::make('users') ->label(__('Users')) ->multiple() ->reactive() ->afterStateUpdated(function (Closure $set, $state) { $set('user_group', null); $set('select_all', false); }) ->required() ->disabled(function(?UserEvent $record){ if(!empty($record)){ return true; } }) ->options($options) and i use the model class protected function getFormModel(): String { return UserEvent::class; } and i use $this->form->model($userEvent); why the disabled function only works on component init ?
Want results from more Discord servers?
Add your server
More Posts