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
When creating custom fields, you may want to exclude certain base fields that don't apply to your field type. For example, a Repeater field doesn't need a "Default value" field since it's a container for other fields.
279
+
280
+
You can exclude base fields by overriding the `excludeFromBaseSchema()` method:
281
+
282
+
```php
283
+
<?php
284
+
285
+
namespace App\Fields;
286
+
287
+
use Backstage\Fields\Fields\Base;
288
+
289
+
class RepeaterField extends Base
290
+
{
291
+
// Exclude the default value field since it doesn't make sense for repeaters
292
+
protected function excludeFromBaseSchema(): array
293
+
{
294
+
return ['defaultValue'];
295
+
}
296
+
297
+
// Your field implementation...
298
+
}
299
+
```
300
+
301
+
Available base fields that can be excluded:
302
+
-`required` - Required field toggle
303
+
-`disabled` - Disabled field toggle
304
+
-`hidden` - Hidden field toggle
305
+
-`helperText` - Helper text input
306
+
-`hint` - Hint text input
307
+
-`hintColor` - Hint color picker
308
+
-`hintIcon` - Hint icon input
309
+
-`defaultValue` - Default value input
310
+
311
+
#### Best practices for field exclusion
312
+
313
+
-**Only exclude what doesn't apply**: Don't exclude fields just because you don't use them - only exclude fields that conceptually don't make sense for your field type
314
+
-**Document your exclusions**: Add comments explaining why certain fields are excluded
315
+
-**Test thoroughly**: Make sure your field still works correctly after excluding base fields
316
+
-**Consider inheritance**: If your field extends another custom field, make sure to call `parent::excludeFromBaseSchema()` if you need to add more exclusions
317
+
318
+
Example of a field that excludes multiple base fields:
319
+
320
+
```php
321
+
class ImageField extends Base
322
+
{
323
+
protected function excludeFromBaseSchema(): array
324
+
{
325
+
return [
326
+
'defaultValue', // Images don't have default values
327
+
'hint', // Image fields typically don't need hints
0 commit comments