Skip to content

Commit

Permalink
Update custom-schemata.md
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Jun 9, 2024
1 parent e8c516c commit 2ead25b
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion docs/advanced/custom-schemata.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,60 @@ title: Custom Schemata
weight: 6
---

## Use Custom Schemata
## Add Custom Schema for fields

Bolt allow you to add custom form components to the form, section and fields.

### First: create the class:

create a class where ever you wnt in your app for example in `App\Zeus\CustomSchema` with the content:

```php
<?php

namespace App\Zeus\CustomSchema;

use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\TextInput;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Bolt\Contracts\CustomSchema;
use LaraZeus\Bolt\Fields\FieldsContract;

class Field implements CustomSchema
{
public function make(?FieldsContract $field = null): Accordion
{
return Accordion::make('more-field-options')
->schema([
TextInput::make('options.field.nickname')
->label('field nickname'),
]);
}

public function hidden(?FieldsContract $field = null): array
{
return [
Hidden::make('options.field.nickname'),
];
}
}
```

- make sure to return the hidden fields the same as the fields you have defined in the `make` method
- make sure to set the `state` correctly, if you want to store these info in the `options` then use `options.more-data`, or in separate column then make sure to create the migration for it

### Second: add it to your panel config:

```php
BoltPlugin::make()
->customSchema([
'form' => null,
'section' => null,
'field' => \App\Zeus\CustomSchema\Field::class,
])
```

## Replace the Schemata with Custom one

the trait `Schemata` is the heart of the form builder, and now you can customize it to your liking.

Expand Down

0 comments on commit 2ead25b

Please sign in to comment.