You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
->availableValidationRules($rules) // Validation rules users can toggle per field
197
+
->defaultValidationRules($rules) // Validation rules always applied to this field type
198
+
->searchable() // Enable globally-searchable in tables (default: true)
199
+
->sortable() // Enable column sorting in tables (default: true)
200
+
->filterable() // Enable table filter for this field type (default: false)
201
+
->encryptable() // Allow users to enable encryption for this field
202
+
```
203
+
204
+
::callout{type="info"}
205
+
A field type needs **both**`filterable()` and `tableFilter()` for filters to appear in tables. `filterable()` enables the capability; `tableFilter()` provides the filter component.
206
+
::
207
+
208
+
### Settings
209
+
210
+
Add type-specific configuration options that appear in the field editor when your field type is selected. Settings are stored per custom field instance.
211
+
212
+
`withSettings()` takes two arguments:
213
+
1. A [Spatie Laravel Data](https://spatie.be/docs/laravel-data/v4/introduction) class defining the settings structure
214
+
2. An array of Filament form components (or a `Closure` returning them) for the settings UI
215
+
216
+
```php
217
+
use Spatie\LaravelData\Data;
218
+
use Filament\Forms\Components\TextInput;
219
+
220
+
class CurrencySettings extends Data
221
+
{
222
+
public function __construct(
223
+
public string $currencySymbol = '$',
224
+
public int $decimalPlaces = 2,
225
+
) {}
226
+
}
227
+
228
+
// In your field type's configure() method:
229
+
return FieldSchema::float()
230
+
->key('acme-currency')
231
+
->label('Currency')
232
+
->withSettings(CurrencySettings::class, [
233
+
TextInput::make('currency_symbol')
234
+
->label('Currency Symbol')
235
+
->default('$'),
236
+
TextInput::make('decimal_places')
237
+
->label('Decimal Places')
238
+
->numeric()
239
+
->default(2),
240
+
]);
241
+
```
242
+
243
+
The settings form components are automatically shown/hidden based on the selected field type. Access stored settings via `$customField->settings` in your component closures.
244
+
245
+
### Multi-Value & Constraints
246
+
247
+
Control whether users can store multiple values in a single field and enforce uniqueness.
248
+
249
+
```php
250
+
->supportsMultiValue()
251
+
->supportsUniqueConstraint()
252
+
->defaultItemValidationRules($rules)
253
+
->requiresLookupType()
254
+
```
255
+
256
+
**`supportsMultiValue()`** -- Shows an "Allow Multiple Values" toggle in the field editor. When enabled by the user, the field accepts multiple values (e.g., multiple emails or phone numbers) and a "Max Values" input appears. Used by Email, Phone, Link, and Record field types.
257
+
258
+
**`supportsUniqueConstraint()`** -- Shows a "Unique per Entity Type" toggle in the field editor. When enabled by the user, a `UniqueCustomFieldValue` validation rule is applied to prevent duplicate values across records of the same entity type. Used by Email, Phone, Link, Text, Textarea, and Number field types.
259
+
260
+
**`defaultItemValidationRules(array $rules)`** -- Validation rules automatically applied to **each individual item** in a multi-value field. These are not user-configurable -- they are hardcoded per field type. Only available for `MULTI_CHOICE` data types; throws `InvalidArgumentException` otherwise.
261
+
262
+
**`requiresLookupType()`** -- Replaces the user-defined options UI with an entity type selector. The field stores references to records of the selected entity type instead of static option values. Import/export treats these as entity references. Currently used by the Record field type.
263
+
264
+
Example -- the Email field type combines these to support multiple unique emails with per-item validation:
// Transform raw import value into the correct storage format
284
+
})
285
+
```
286
+
287
+
**`importExample(string $example)`** -- Displayed as a sample value in the import template UI, helping users understand the expected format for this field type.
288
+
289
+
**`importTransformer(Closure $transformer)`** -- Receives the raw value from the import file and returns the transformed value for storage. Without a transformer, the raw value is stored as-is. The closure signature is `function (mixed $state): mixed`.
290
+
291
+
Example -- the Currency field type strips formatting characters on import:
0 commit comments