Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easyadmin 3 field disabled/read-only

is there any chance to disable an field to user using EasyAdmin's implemented fields?

I would like to show to user a boolean value of "isPaid", but i don't want him to change it, just show him (the payment gateway does this)

Thanks for your help!

like image 731
Jakub Novák Avatar asked Jul 23 '20 13:07

Jakub Novák


People also ask

How to configure easyadmin?

Configuring EasyAdmin Configuration of EasyAdmin is done via convars, these can be set via your server config file or by typing it as a command inside your servers' console (this method may not always work with EasyAdmin and the settings will reset after the server has been restarted.

What are field fields in easyadmin?

Fields allow to display the contents of your Doctrine entities on each CRUD page. EasyAdmin provides built-in fields to display all the common data types, but you can also create your own fields. If your CRUD controller extends from the AbstractCrudController provided by EasyAdmin, the fields are configured automatically.

How to display two fields on the same row in easyadmin?

If you need a better control of the design depending on the device width, you can pass a string with the responsive CSS classes that define the width of the field on different breakpoints: This example adds col-sm-6 to override the default EasyAdmin behavior and display the two fields on the same row also in the sm breakpoint.

How to define fields in easyadmin using PHP generators?

If you need even greater control, consider using the following way of defining the fields using PHP generators: By default, EasyAdmin displays one form field per row. Inside the row, each field type uses a different default width (e.g. integer fields are narrow and code editor fields are very wide).


2 Answers

What you are probably looking for is this:

BooleanField::new('isPaid')->setFormTypeOption('disabled','disabled');
like image 87
Johan Avatar answered Sep 29 '22 07:09

Johan


Actually all i needed and wanted is this:

public function configureFields(string $pageName): iterable
{
    ...
    $isPaid = BooleanField::new('isPaid')->renderAsSwitch(false)->hideOnForm();
    ...
}

Thanks for your help anyway!

like image 29
Jakub Novák Avatar answered Sep 29 '22 06:09

Jakub Novák