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
Copy file name to clipboardExpand all lines: docs/guide/form-fields/autocomplete.md
+55-50Lines changed: 55 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,16 +21,52 @@ This method is useful to link the dataset of a local autocomplete (aka: the `loc
21
21
22
22
### `setRemoteEndpoint(string $remoteEndpoint)`
23
23
24
-
The endpoint to hit with mode=remote.
24
+
The remote endpoint which should return JSON-formatted results. Note that you can add the `sharp_auth` middleware to this route to handle authentication and prevent this API endpoint to be called by non-sharp users:
25
25
26
-
If this endpoint is yours (`remote` mode here is useful to avoid loading a lot of data in the view), you can add the `sharp_auth` middleware to the API route to handle authentication and prevent this API endpoint to be called by non-sharp users:
This endpoint MUST be part of your application. If you need to hit an external endpoint, you should create a custom endpoint in your application that will call the external endpoint (be sure to check the alternative `setRemoteCallback` method).
To avoid the pain of writing a new dedicated endpoint, and for simple cases, you can use this method to provide a callback that will be called when the autocomplete field needs to fetch data. The callback will receive the search string as a parameter and should return an array of objects.
The second argument, `$linkedFields`, allows you to provide a list of fields that will be sent with their values to the callback, so you can filter the results based on the values of other fields.
Set a minimum number of character to type before performing the search.
@@ -61,7 +97,7 @@ Set the remote method to GET (default) or POST.
61
97
In a remote autocomplete case, you can use this method instead of `setRemoteEndpoint` to handle a dynamic URL, based on another form field. Here's how, for example:
The templates for the list and result items can be set in two ways: either by passing a string, or by passing a Laravel view.
98
133
99
-
```php
100
-
$panel->setInlineTemplate(
101
-
'Foreground: <strong>{{color}}</strong>'
102
-
)
103
-
```
104
-
105
-
The template will be used, depending on the function, to display either the list item (in the result dropdown) or the result item (meaning the valuated form input).
106
-
107
-
Be aware that you'll need for this to work to pass a valuated object to the Autocomplete, as data.
Use this if you need more control: give the path of a full template, in its own file.
113
-
114
-
The template will be [interpreted by Vue.js](https://vuejs.org/v2/guide/syntax.html), meaning you can add data placeholders, DOM structure but also directives, and anything that Vue will parse. For instance:
115
-
116
-
```vue
117
-
<div v-if="show">result is {{value}}</div>
118
-
<div v-else>result is unknown</div>
119
-
```
120
-
121
-
The template will be used, depending on the function, to display either the list item (in the result dropdown) or the result item (meaning the valuated form input).
122
-
123
-
Be aware that you'll need for this to work to pass a valuated object to the Autocomplete, as data.
124
-
125
-
### `setAdditionalTemplateData(array $data)`
126
-
127
-
Useful to add some static (or at least not instance-dependant) data to the template. For instance:
134
+
Examples:
128
135
129
136
```php
130
-
SharpFormAutocompleteRemoteField::make('brand')
131
-
->setAdditionalTemplateData([
132
-
'years' => [2020, 1018, 2017]
133
-
]);
134
-
```
135
-
136
-
In the template, the provided data can be used as normal:
Copy file name to clipboardExpand all lines: docs/guide/upgrading/9.0.md
+57-9Lines changed: 57 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -495,7 +495,11 @@ class PostBlockList extends SharpEntityList
495
495
496
496
You can of course instead declare a real Filter.
497
497
498
-
## SharpFormGeolocationField using Google Maps API must now provide a Map ID
498
+
## Localization feature was removed for `SharpFormSelectField`, `SharpFormTagsField` and `SharpFormAutocompleteField` fields
499
+
500
+
Those fields could be localized in 8.x it a weird way: **labels** were localized, but not **values**. This was a really misleading, so we decided to remove entirely this behavior in 9.x. The only real impact should be to remove setLocalized() calls in your code for these fields.
501
+
502
+
## `SharpFormGeolocationField` using Google Maps API must now provide a Map ID
499
503
500
504
Sharp 9.x now uses Advanced Markers which requires a [Map ID](https://developers.google.com/maps/documentation/get-map-id), register it with the following method of the field :
501
505
@@ -515,15 +519,15 @@ class PostForm extends SharpForm
515
519
```
516
520
517
521
518
-
## SharpFormAutocompleteFormField was split in two subclasses for local and remote cases
522
+
## `SharpFormAutocompleteFormField` was rewritten and need to be migrated
519
523
520
-
REWRITE THIS WITH:
521
-
- no more `setAdditionalTemplateData`
522
-
-
524
+
First, the `SharpFormAutocompleteFormField` class was split into two classes: `SharpFormAutocompleteLocalField` and `SharpFormAutocompleteRemoteField`, to clearly separate these two different use cases.
523
525
524
-
This isn’t a breaking change, since `SharpFormAutocompleteFormField::make($key, $mode)` is still supported, but deprecated. You should migrate to the new `SharpFormAutocompleteLocalField` and `SharpFormAutocompleteRemoteField` classes.
526
+
Second, Vue templates must be migrated to Blade templates (similar to the `SharpWidgetPanel` or Page Alerts migrations). You can either pass a view name or a blade template directly to the newly named `setListItemTemplate()` and `setResultItemTemplate()` methods (the old `setListItemInlineTemplate()`, `setListItemTemplatePath()`, `setResultItemInlineTemplate()` and `setResultItemTemplatePath()` were removed).
525
527
526
-
In 8.x:
528
+
The `setAdditionalTemplateData()` method was also removed, in favor of a more straightforward way to pass additional data to the template.
529
+
530
+
Example in 8.x:
527
531
528
532
```php
529
533
class PostForm extends SharpForm
@@ -565,8 +569,7 @@ class PostForm extends SharpForm
@@ -585,6 +588,51 @@ class PostForm extends SharpForm
585
588
}
586
589
```
587
590
591
+
Finally, there is a big evolution which concerns the remote autocomplete endpoint: your 8.x implementation should still work, but you should note that:
592
+
- you can now directly write the autocomplete endpoint as a callback closure in the field (no need to use a dedicated route + controller),
593
+
- external endpoint URLs aren’t supported anymore (you must write a wrapper around this external endpoint, either as a route + controller or via the new callback option).
594
+
595
+
Example in 8.x:
596
+
597
+
```php
598
+
class PostForm extends SharpForm
599
+
{
600
+
public function buildFormFields(FieldsContainer $formFields): void
0 commit comments