Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Jun 10, 2024
1 parent 5e2fc50 commit 1173edb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions docs/advanced/custom-schemata.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ weight: 6

## Add Custom Schema for fields

Bolt allow you to add custom form components to the form, section and fields.
Bolt allows you to add custom components (additional metadata) to the form, sections, 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:
Create a class wherever you want in your app for example in `App\Zeus\CustomSchema` with the content:

```php
<?php
Expand All @@ -26,24 +26,24 @@ class Field implements CustomSchema
{
public function make(?FieldsContract $field = null): Accordion
{
return Accordion::make('more-field-options')
return Accordion::make('meta-data')
->schema([
TextInput::make('options.field.nickname')
->label('field nickname'),
TextInput::make('options.meta.data_binding')
->label('Data Binding'),
]);
}

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

- 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
- make sure to set the `state` correctly, if you want to store this info in the `options` then use `options. more data, or in a separate column then make sure to create the migration for it

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

Expand All @@ -56,6 +56,18 @@ BoltPlugin::make()
])
```

### Third: catch it on the `FormSent` event, for example:

```php
$event->response->fieldsResponses->each(function($fieldResponse){
CustomeModel::create([
'column' => $fieldResponse->field->options['meta']['data_binding']
]);
});
```

_**Warning: This is a simplified example, so don't trust your user input explicitly. That could open some pretty serious security holes.**

## 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 All @@ -67,12 +79,12 @@ the trait `Schemata` is the heart of the form builder, and now you can customize

copy the trait from `\LaraZeus\Bolt\Concerns` to your app, let say: `\App\Zeus\Bolt\Concerns`

### call the trait in a service provider
### Call the trait in a service provider

in your register method of your `AppServiceProvider` add the following:

```php
\LaraZeus\Bolt\Livewire\FillForms::getBoltFormDesignerUsing(\App\Zeus\Bolt\Concerns\Designer::class);
```

You're done. Customize the form builder to fit your needs. Remember to keep an eye on any changes in future updates so that you will avoid breaking changes.
You're done. Customize the form builder to fit your needs. Remember to keep an eye on any changes in future updates so that you will avoid breaking changes.

0 comments on commit 1173edb

Please sign in to comment.