Fields
Fields
Fields are the base element of any Flex application. Fields are created using the static function make().
The key is usually the column name for the model. We use PHP option chaining for the field definition since the make function will return null when the $keys array does not contain the key for the field.
File: PropertyResource.php
use Psi\FlexAdmin\Fields\Field;
use Psi\FlexAdmin\Resources\Flexible;
use Psi\FlexAdmin\Resources\Resource;
class PropertyResource extends Resource implements Flexible
{
/**
* Create fields for resource
*
* @param array|null|null $cols input list of columns enabled for the resource in context, null is prior to column availability
* @return array
*/
public function fields(array|null $keys = null): array
{
return [
// Field::make(array|null $keys, string $key)
Field::make(keys: $keys, key: 'id')
?->name('propertyId')
];
}
}
Info
This would setup a field with an output name 'propertyId' using the 'id' attribute of the resource.
Attributes
Name
Optional name for the field. The default will be the same as the key
Field::make($keys,'id')
?->name('myFieldName')
Attributes
These attributes are appended to the field attributes and can designate any additional attributes available to the field's rendering component.
Field::make($keys,'name')
?->attributes(
[
'color' => 'secondary',
'textColor' => 'white',
'size' => 'sm'
]
)
Copyable
Add a copy button to the field where supported by the rendering component. The copy will copy the field value to the clipboard.
Field::make($keys, 'text')
?->copyable()
Selectable
Add a selectable attribute to the field where components enable rendering the field value for easy selection.
Note
Not all components will allow for a selectable field
Field::make($keys, 'text')
?->selectable()
Sortable
Indicates the field is sortable. The field must be sortable to enable correct sorting.
Field::make($keys, 'text')
?->sortable()
Default Sort
Make the field the default sort field and set the sort direction.
Field::make($keys, 'name')
?->sortable()
->defaultSort('desc')
Searchable
Designating a field as searchable enables calling the flex search function when the field name is present on the request scope.
Field::make($keys, 'name')
?->searchable()
Filterable
Designating a field as filterable indicates the query should be filtered when the attribute name is present on the request scope
Field::make($keys, 'name')
?->filterable()
Icon
Add an icon display to the field. Most field components would render an icon value.
Note
Icons may not display in all contexts.
Field::make($keys, 'name')
?->icon('mdi-account')
Readonly
Hidden
Value Only
Add To Values
Display Control
->indexOnly() // Field is enabled only for index context
->detailOnly() // Field is enabled only for detail context
->editOnly() // Field is enabled only for edit context
->createOnly() // Field is enabled only for create context
->hideFromIndex() // Disabled from index, other contexts are valid, only enabled attribute
->hidefromDetail() // Disabled from detail context, only effects enabled attribute
->hideFromEdit() // Disabled form edit context, only effects enabled attribute
->hideFromCreate() // Disabled from create context, only effects enabled attribute
Permissions
->withoutPermissions() // Ignore permissions when rendering to array and enabling field
->indexPermission($permission) // Specific permission to use with index context to enable field, default is view-any (i.e. users.view-any)
->detailPermission($permission) // Specific permission to use with detail context to enable field, default is view (i.e. users.view)
->createPermission($permission) // Specific permission to use with create context to enable field, default is edit (i.e. users.edit)
->editPermission($permission) // Specific permission to use with edit cotnext to enable field, default is create (i.e. users.create)
->withPermissions($context,$model) // Enables the field based on the context and model plural name
Render
->component($component) // specify the default component to use for rendering
->panel($panel) // group the field with the panel specified
->createComponent($component) // Specific component to use for create context
->detailComponent($component) // Specific component to use in detail context
->editComponent($component) // Specific component to use in edit context
->indexComponent($component) // Specific component for index context
Value
->default( $value ) // sets a default value for the field
->value( $value ) // sets the field value, can be a callable function
