Skip to content

Commit 4289bd1

Browse files
committed
docs: add configuration guide for Select2 with multiple AJAX URLs
1 parent 2e21aa9 commit 4289bd1

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

docs/basic-usage/select2.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,36 @@ This will allow users to enter their own values if no options are available. Whe
9595
<x-forms::submit>Submit</x-forms::submit>
9696
</x-forms::form>
9797
```
98+
# Configuring a Select2 element to search from multiple URLs
99+
100+
You can configure a Select2 element to be able to search from multiple URLs, depending on the selected value of another select element.
101+
102+
Imagine you want to build a menu builder for your application, and you want to allow users to be able to select a menu item type (e.g. courses, job listings, employers) and then search for the items of that type.
103+
104+
You can do this by using the `ajax-child` and `is-first` attribute on the type select field, and then use `is-ajax`, `ajax-url` and `selected-url` attributes on the child select field.
105+
106+
```html
107+
@php
108+
$menu_item_types = ['jobs' => 'Jobs', 'employers' => 'Employers'];
109+
$urls = ['jobs' => 'https://example.com/api/jobs', 'employers' => 'https://example.com/api/employers'];
110+
@endphp
111+
112+
<x-forms::select2
113+
name="post_type"
114+
:options="$menu_item_types"
115+
ajax-child="#model_id"
116+
is-first
117+
allow-clear
118+
placeholder="Nothing Selected"
119+
/>
120+
121+
<x-forms::select2
122+
name="post_id"
123+
is-ajax
124+
:ajax-url="json_encode($urls)"
125+
placeholder="Select a post to link"
126+
allow-clear
127+
selected-url=""
128+
/>
129+
130+
```

0 commit comments

Comments
 (0)