Overview
Field classes can be found in theFilament\Form\Components namespace.
Fields reside within the schema of your form, alongside any layout components.
Fields may be created using the static make() method, passing its unique name. The name of the field should correspond to a property on your Livewire component. You may use “dot notation” to bind fields to keys in arrays.
Available fields
Filament ships with many types of field, suitable for editing different types of data:- Text input
- Select
- Checkbox
- Toggle
- Checkbox list
- Radio
- Date-time picker
- File upload
- Rich editor
- Markdown editor
- Repeater
- Builder
- Tags input
- Textarea
- Key-value
- Color picker
- Toggle buttons
- Hidden
Setting a label
By default, the label of the field will be automatically determined based on its name. To override the field’s label, you may use thelabel() method. Customizing the label in this way is useful if you wish to use a translation string for localization:
translateLabel() method:
Setting an ID
In the same way as labels, field IDs are also automatically determined based on their names. To override a field ID, use theid() method:
Setting a default value
Fields may have a default value. This will be filled if the form’sfill() method is called without any arguments. To define a default value, use the default() method:
Adding helper text below the field
Sometimes, you may wish to provide extra information for the user of the form. For this purpose, you may add helper text below the field. ThehelperText() method is used to add helper text:
Illuminate\Support\HtmlString or Illuminate\Contracts\Support\Htmlable. This allows you to render HTML, or even markdown, in the helper text:
Adding a hint next to the label
As well as helper text below the field, you may also add a “hint” next to the label of the field. This is useful for displaying additional information about the field, such as a link to a help page. Thehint() method is used to add a hint:
Illuminate\Support\HtmlString or Illuminate\Contracts\Support\Htmlable. This allows you to render HTML, or even markdown, in the helper text:
Changing the text color of the hint
You can change the text color of the hint. By default, it’s gray, but you may usedanger, info, primary, success and warning:
Adding an icon aside the hint
Hints may also have an icon rendered next to them:Adding a tooltip to a hint icon
Additionally, you can add a tooltip to display when you hover over the hint icon, using thetooltip parameter of hintIcon():
Adding extra HTML attributes
You can pass extra HTML attributes to the field, which will be merged onto the outer DOM element. Pass an array of attributes to theextraAttributes() method, where the key is the attribute name and the value is the attribute value:
<input> or <select> DOM element, but this is often not the outer element in the field, so the extraAttributes() method may not work as you wish. In this case, you may use the extraInputAttributes() method, which will merge the attributes onto the <input> or <select> element:
Disabling a field
You may disable a field to prevent it from being edited by the user:dehydrated() method:
If you choose to dehydrate the field, a skilled user could still edit the field’s value by manipulating Livewire’s JavaScript.
Hiding a field
You may hide a field:Autofocusing a field when the form is loaded
Most fields are autofocusable. Typically, you should aim for the first significant field in your form to be autofocused for the best user experience. You can nominate a field to be autofocused using theautofocus() method:
Setting a placeholder
Many fields will also include a placeholder value for when it has no value. This is displayed in the UI but not saved if the field is submitted with no value. You may customize this placeholder using theplaceholder() method:
Marking a field as required
By default, required fields will show an asterisk* next to their label. You may want to hide the asterisk on forms where all fields are required, or where it makes sense to add a hint to optional fields instead:
required(), but you still wish to show an asterisk * you can use markAsRequired() too:
Global settings
If you wish to change the default behavior of a field globally, then you can call the staticconfigureUsing() method inside a service provider’s boot() method or a middleware. Pass a closure which is able to modify the component. For example, if you wish to make all checkboxes inline(false), you can do it like so: