Skip to content

Commit 6f1f035

Browse files
authored
Merge pull request #639 from Laravel-Backpack/add-docs-for-modal-form-component
2 parents bac899e + 7a7cd52 commit 6f1f035

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

7.x-dev/base-components.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ These are the components that Backpack uses inside the default CRUD operations.
9090

9191
![Backpack v7 Dataform component](https://backpackforlaravel.com/uploads/v7/dataform_component.jpg)
9292

93-
This component helps you show a form _anywhere you want_, so the admin to easily create or edit an entries for an Eloquent model. The dataform component is a extension of a CrudController - so a CrudController for that entity needs to be already set up, and passed to this component as a parameter:
93+
This component helps you show a form _anywhere you want_, so the admin can easily create or edit an entries for an Eloquent model. The dataform component is a extension of a CrudController - so a CrudController for that entity needs to be already set up, and passed to this component as a parameter:
9494

9595
```html
9696
<x-bp-dataform controller="\App\Http\Controllers\Admin\InvoiceCrudController" />
9797
```
9898

9999
**Configuration options:**
100-
- `name='invoice_form'` - by default, a name will be generated; but you can pick one you can recognize;
101100
- `operation='create'` - by default, the datatable component will pick up everything that controller sets up for the Create operation; if you want to change the operation it will initialize, you can pass this parameter;
102101
- `:entry="\App\Models\Invoice::find(1)"` - if you want to use UpdateOperation or a custom form operation that needs the entry;
103102
- `:setup="function($crud, $parent) {}"` - if you want to make changes to the operation setup (eg. add/remove fields, configure functionality), you can use this parameter; the closure passed here will be run _after_ the setup of that operation had already completed;
@@ -118,6 +117,47 @@ This component helps you show a form _anywhere you want_, so the admin to easily
118117

119118
<hr>
120119

120+
<a name="dataform-modal"></a>
121+
### Dataform Modal
122+
123+
![Backpack v7 Dataform Modal component](https://backpackforlaravel.com/uploads/v7/dataform_component.jpg)
124+
125+
This component helps you show a form _anywhere you want_ inside a modal, so the admin can easily create or edit an entry for an Eloquent model without having to refresh the whole page.
126+
127+
To use this component you are required to add `CreateInModalOperation` and/or `UpdateInModalOperation` in your CrudController. The dataform modal component is a extension of a CrudController - so a CrudController for that entity needs to be already set up, and passed to this component as a parameter:
128+
129+
First, in your CrudController, either remove `CreateOperation` in favor of `CreateInModalOperation`, or you can keep both operations. Having both of them is usefull if you want your ListOperation to still show the regular "Create" button, but you would like also to have the possibility to create this entity somewhere else in your application using a modal form.
130+
131+
```php
132+
use \Backpack\DataformModal\Http\Controllers\Operations\CreateInModalOperation;
133+
```
134+
135+
```html
136+
<x-bp-dataform-modal controller="\App\Http\Controllers\Admin\InvoiceCrudController" />
137+
```
138+
139+
**Configuration options:**
140+
- `operation='createInModal'` - by default, the component will pick up everything that controller sets up for the Create operation; if you want to change the operation it will initialize, you can pass this parameter, eg: `updateInModal`
141+
- `:entry="\App\Models\Invoice::find(1)"` - if you want to use UpdateInModalOperation or a custom form operation that needs the entry;
142+
- `:setup="function($crud, $parent) {}"` - if you want to make changes to the operation setup (eg. add/remove fields, configure functionality), you can use this parameter; the closure passed here will be run _after_ the setup of that operation had already completed;
143+
144+
**Advanced example:**
145+
146+
```html
147+
<x-bp-dataform-modal
148+
controller="\App\Http\Controllers\Admin\InvoiceCrudController"
149+
name="invoice_form"
150+
operation="updateInModal"
151+
:entry="\App\Models\Invoice::find(1)"
152+
:setup="function($crud, $parent) {
153+
$crud->removeColumn('notes');
154+
}"
155+
/>
156+
```
157+
<hr>
158+
159+
> **NOTE**: The date_picker (jquery version) does not properly work in this context. Please use any alternative.
160+
121161
<a name="datatable"></a>
122162
### Datatable
123163

0 commit comments

Comments
 (0)