Visibility
A form is rendered in one of three operations, the constants of
Anvil\Schema\FormContext: CREATE ('create'), EDIT ('edit') and
VIEW ('view', the detail page). Every component can be hidden in some of
them; fields can also be disabled:
use Anvil\Schema\FormContext;
TextInput::make('personnel_number')->required()->disabledOn(FormContext::EDIT),Select::make('status')->options(self::STATUSES)->disabled()->hiddenOn(FormContext::CREATE),PasswordInput::make('password')->required()->hiddenOn(FormContext::EDIT, FormContext::VIEW),Tab::make('Secret')->hiddenOn(FormContext::VIEW)->schema([...]),| Method | On fields | On layouts |
|---|---|---|
hiddenOn(...) |
not rendered, not validated and not written in these operations | not rendered, nor are their fields |
disabledOn(...) |
rendered, never written in these operations | – |
disabled() |
rendered, never written | – |
Security
Section titled “Security”What is not written cannot be changed by a manipulated request either: the server builds the validation rules and the saved data from the fields that are writable in the current operation. A disabled field shows its value but a submitted value is ignored.
Hidden layouts
Section titled “Hidden layouts”A layout hidden in an operation hides all fields inside it, also those of
nested layouts: they are neither validated nor written, so a section
hidden on edit keeps its saved values. On the detail page and in the API
answer (operation view) they are left out as well.
Typical cases
Section titled “Typical cases”| Case | Definition |
|---|---|
| set once, then fixed | disabledOn(FormContext::EDIT) |
| set by the system, shown | disabled()->hiddenOn(FormContext::CREATE) |
| only when creating | hiddenOn(FormContext::EDIT, FormContext::VIEW) |
| never on the detail page | hiddenOn(FormContext::VIEW) |
No conditions on values
Section titled “No conditions on values”Visibility depends only on the operation. There is no visibility that
depends on the values of other fields (e.g. “show the end date when
Limited is checked”); the server always validates the complete schema.
Check such dependencies in the model or with
EndpointException::forValidation() in the resource, see
Loading and saving.