mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-06 17:51:34 +02:00
* First cut * Temporarily disable composer.json for netlify build * POC * New recursive directory query, various refinements * Fix flexbox * new styled components plugin * Apply frontmatter delimiters * Mobile styles, animation * Search * Redesign, clean up * Nuke the cache, try again * fix file casing * Remove production env file * ID headers * Move app to new repo * Add frontmatter universally * Hide children changelogs * Add how to title * New callout tags * Revert inline code block change * Replace note callouts * Fix icons * Repalce images * Fix icon * Fix image links * Use proper SQL icon
69 lines
1.8 KiB
Markdown
69 lines
1.8 KiB
Markdown
---
|
|
title: Form Transformations
|
|
summary: Provide read-only and disabled views of your Form data.
|
|
icon: random
|
|
---
|
|
|
|
# Read-only and Disabled Forms
|
|
|
|
[Form](api:SilverStripe\Forms\Form) and [FormField](api:SilverStripe\Forms\FormField) instances can be turned into a read-only version for things like confirmation pages or
|
|
when certain fields cannot be edited due to permissions. Creating the form is done the same way and markup is similar,
|
|
`readonly` mode converts the `input`, `select` and `textarea` tags to static HTML elements like `span`.
|
|
|
|
To make an entire [Form](api:SilverStripe\Forms\Form) read-only.
|
|
|
|
|
|
```php
|
|
use SilverStripe\Forms\Form;
|
|
|
|
$form = new Form(..);
|
|
$form->makeReadonly();
|
|
```
|
|
|
|
To make all the fields within a [FieldList](api:SilverStripe\Forms\FieldList) read-only (i.e to make fields read-only but not buttons).
|
|
|
|
|
|
```php
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
$fields = new FieldList(..);
|
|
$fields = $fields->makeReadonly();
|
|
```
|
|
|
|
To make a [FormField](api:SilverStripe\Forms\FormField) read-only you need to know the name of the form field or call it direct on the object
|
|
|
|
|
|
```php
|
|
use SilverStripe\Forms\TextField;
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
$field = new TextField(..);
|
|
$field = $field->performReadonlyTransformation();
|
|
|
|
$fields = new FieldList(
|
|
$field
|
|
);
|
|
|
|
// Or,
|
|
$field = new TextField(..);
|
|
$field->setReadonly(true);
|
|
|
|
$fields = new FieldList(
|
|
$field
|
|
);
|
|
```
|
|
|
|
## Disabled FormFields
|
|
|
|
Disabling [FormField](api:SilverStripe\Forms\FormField) instances, sets the `disabled` property on the class. This will use the same HTML markup as
|
|
a normal form, but set the `disabled` attribute on the `input` tag.
|
|
|
|
```php
|
|
$field = new TextField(..);
|
|
$field->setDisabled(true);
|
|
|
|
echo $field->forTemplate();
|
|
|
|
// returns '<input type="text" class="text" .. disabled="disabled" />'
|
|
```
|