diff --git a/docs/advanced/custom-schemata.md b/docs/advanced/custom-schemata.md index ba16fb77..62c8a093 100644 --- a/docs/advanced/custom-schemata.md +++ b/docs/advanced/custom-schemata.md @@ -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 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: @@ -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. @@ -67,7 +79,7 @@ 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: @@ -75,4 +87,4 @@ in your register method of your `AppServiceProvider` add the following: \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. \ No newline at end of file