Skip to content

Commit

Permalink
Merge pull request #575 from Laravel-Backpack/cleanup-select2-ajax-docs
Browse files Browse the repository at this point in the history
cleanup select2 from json
  • Loading branch information
pxpm authored Apr 30, 2024
2 parents fda9d79 + 2db9289 commit 87f6b70
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions 6.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -2356,23 +2356,22 @@ Similar to [select2_from_ajax](#section-select2_from_ajax) above, but this one i

```php
CRUD::field([
'label' => 'Airports', // Table column heading
'label' => 'Airports', // Displayed column label
'type' => 'select2_json_from_api',
'name' => 'airports', // a unique identifier (usually the method that defines the relationship in your Model)
'data_source' => url('airports/fetch/list'), // url to controller search function (with /{id} should return model)
'name' => 'airports', // the column where this field will be stored
'data_source' => url('airports/fetch/list'), // the endpoint used by this field

// OPTIONAL
'delay' => 500, // the minimum amount of time between ajax requests when searching in the field
'method' => 'POST', // route method, either GET or POST
'placeholder' => 'Select an airport', // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'multiple' => true, // allow multiple selections
'method' => 'POST', // HTTP method to use for the AJAX call (GET, POST)
'include_all_form_fields' => false, // only send the current field through AJAX (for a smaller payload if you're not using multiple chained select2s)

// OPTIONAL - if the response is a list of objects (and not a simple array)
'attribute' => 'title', // foreign key attribute that is shown to user
'stored_attributes' => ['id', 'title'], // attributes to store in the database
'attribute' => 'title', // attribute to show in the select2
'attributes_to_store' => ['id', 'title'], // attributes to store in the database
]);
```

Expand All @@ -2382,7 +2381,7 @@ You may create a controller and routes for the data_source above. Here's an exam
Note that this example is for a non paginated response, but `select2_json_from_api` also accepts a paginated response.

```php
// use the FetchOperation
// use the FetchOperation to quickly create an endpoint
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
```

Expand Down

0 comments on commit 87f6b70

Please sign in to comment.