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
This is a package for [Laravel Backpack](https://laravel-backpack.readme.io/docs) and provides CRUD field types which allow to create a related CRUD entity on-the-fly while adding/editing another.
11
+
This is a package for [Laravel Backpack](https://laravel-backpack.readme.io/docs) and provides CRUD field types which allow to create and edit a related CRUD entity on-the-fly while adding/editing another.
To use instant creation capability of these field types you have to add the `on-the-fly` key and set a name for the entity.
72
+
For `select2_from_ajax` also "edit" is available.
72
73
74
+
### Field Definition
75
+
76
+
Please set the `$ajaxEntity` property by using the setter in the `setup()`-method of the (foreign) EntityCrudController that is **triggered** by an "instant field":
77
+
78
+
```php
79
+
<?php
80
+
81
+
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
82
+
83
+
class EntityCrudController extends CrudController
84
+
{
85
+
use InstantFields;
86
+
87
+
public function setup()
88
+
{
89
+
// other Backpack options
90
+
91
+
$this->setAjaxEntity('entity');
92
+
93
+
// fields/columns definitions
94
+
}
95
+
}
73
96
```
74
-
'on_the_fly' => [
75
-
'entity' => 'entity' // e.g. user, contact, company, job etc...
76
-
]
77
-
```
97
+
98
+
In the field definition of the `EntityCrudController` where your instant field is setup you will have to set the above name in the `on_the_fly`-Array.
78
99
79
-
If you use Laravel Backpack Crud >=3.4.11 you don't have to publish the provided fields, you can use them directly from the package by using the `view_namespace` key.
100
+
> Note: If you use Laravel Backpack Crud >=3.4.11 you don't have to publish the provided fields, you can use them directly from the package by using the `view_namespace` key.
80
101
81
102
Example:
82
103
@@ -93,39 +114,22 @@ Example:
93
114
'pagination' => 20, // optional, default: 10
94
115
'minimum_input_length' => 0,
95
116
'on_the_fly' => [
96
-
'entity' => 'entity',
97
-
'attribute' => 'name' // optional, default: name
117
+
'entity' => 'entity', // e. g. user, contact, company etc...
118
+
119
+
// optional:
120
+
121
+
'create' => false
122
+
'edit' => false
123
+
'create_modal' => 'path to custom create modal'
124
+
'edit_modal' => 'path to custom edit modal'
125
+
'attribute' => '...' // see auto-fill below in readme
98
126
],
99
127
'dependencies' => ['field1', 'field2'...], // optional, resets this field when changing the given ones
100
128
],
101
129
```
102
130
103
131
Instant Fields will try to auto-fill the select2 input after creating a new entry. It will assume that an input field exists with the name `name` and will use its value for the triggered ajax search. If you want to use another field for this, just add `attribute` to the `on_the_fly`-array containing the field name you want to use.
104
132
105
-
## Multiple instant fields
106
-
107
-
If you want to use more than one instant field in a CrudController you have to set the `$ajaxEntity` property by using the setter in the `setup()`-method of the EntityCrudController that is triggered by an "instant field". This has to be the same name as in the field definition:
108
-
109
-
```php
110
-
<?php
111
-
112
-
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
113
-
114
-
class EntityCrudController extends CrudController
115
-
{
116
-
use InstantFields;
117
-
118
-
public function setup()
119
-
{
120
-
// other Backpack options
121
-
122
-
$this->setAjaxEntity('entity');
123
-
124
-
// fields/columns definitions
125
-
}
126
-
}
127
-
```
128
-
129
133
## List view
130
134
131
135
With this package your are also able to add a create button for the foreign CRUD entity in your list view of Backpack! Just add the following line in your `EntityCrudController`:
@@ -192,7 +196,7 @@ If needed you are free to use the `data_source` attribute from the original fiel
192
196
193
197
### Request validation
194
198
195
-
You can also use Request Validation! Just set the `$ajaxStoreRequest` property by using the provided setter method:
199
+
You can also use Request Validation! Just set the `$ajaxStoreRequest`and/or `$ajaxUpdateRequest`property by using the provided setter method:
196
200
197
201
```php
198
202
<?php
@@ -209,11 +213,22 @@ class EntityCrudController extends CrudController
Instant Fields will try to auto-fill the select2 input after creating a new entry. It will assume that an input field exists with the name `name` and will use its value for the triggered ajax search. If you want to use another field for this, just add `attribute` to the `on_the_fly`-array containing the field name you want to use:
0 commit comments