Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 106a02a

Browse files
authored
Merge pull request #5354 from serhiyzhovnir/update-multiselect-widget-documentation
Update Multiselect Widget Documentation
2 parents aecc9eb + 7b8b4e0 commit 106a02a

File tree

1 file changed

+140
-34
lines changed

1 file changed

+140
-34
lines changed

guides/v2.2/javascript-dev-guide/widgets/widget-multiselect.md

Lines changed: 140 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ The following example shows how to instantiate the Multiselect widget:
1919
$("#multiselect").multiselect2({});
2020
```
2121

22-
Where:
23-
24-
- `#multiselect` is the selector of the select element for which Multiselect is initialized.
22+
where `#multiselect` is the selector of the select element for which Multiselect is initialized.
2523

2624
The following example shows a PHTML file using the script:
2725

@@ -42,31 +40,40 @@ The following example shows a PHTML file using the script:
4240

4341
The RedirectUrl widget has the following options:
4442

45-
- [mselectContainer](#mselectcontainer)
46-
- [mselectItemsWrapperClass](#mselectitemswrapperclass)
47-
- [mselectCheckedClass](#mselectcheckedclass)
48-
- [containerClass](#containerclass)
49-
- [searchInputClass](#searchinputclass)
50-
- [selectedItemsCountClass](#selecteditemscountclass)
51-
- [currentPage](#currentpage)
52-
- [lastAppendValue](#lastappendvalue)
53-
- [updateDelay](#updatedelay)
43+
- [containerClass](#containerclass)
44+
- [currentPage](#currentpage)
45+
- [lastAppendValue](#lastappendvalue)
46+
- [mselectCheckedClass](#mselectcheckedclass)
47+
- [mselectContainer](#mselectcontainer)
48+
- [mselectItemsWrapperClass](#mselectitemswrapperclass)
49+
- [nextPageUrl](#nextpageurl)
50+
- [searchInputClass](#searchinputclass)
51+
- [selectedItemsCountClass](#selecteditemscountclass)
52+
- [updateDelay](#updatedelay)
5453

55-
### `mselectContainer`
54+
### `containerClass`
5655

57-
Multiselect container selector.
56+
The class which is attached to the container with [multi-select container selector](#mselectcontainer).
5857

5958
**Type**: String
6059

61-
**Default value**: `'section.mselect-list'`
60+
**Default value**: `'paginated'`
6261

63-
### `mselectItemsWrapperClass`
62+
### `currentPage`
6463

65-
Multiselect items wrapper class.
64+
Current page of multi-select items.
6665

67-
**Type**: String
66+
**Type**: Integer
6867

69-
**Default value**: `'mselect-items-wrapper'`
68+
**Default value**: `1`
69+
70+
### `lastAppendValue`
71+
72+
The value of the last added multi-select item.
73+
74+
**Type**: Integer, String
75+
76+
**Default value**: `0`
7077

7178
### `mselectCheckedClass`
7279

@@ -76,13 +83,48 @@ The class which is attached to a checked multi-select item.
7683

7784
**Default value**: `'mselect-checked'`
7885

79-
### `containerClass`
86+
### `mselectContainer`
8087

81-
The class which is attached to the container with [multi-select container selector](#mselectcontainer).
88+
Multiselect container selector.
8289

8390
**Type**: String
8491

85-
**Default value**: `'paginated'`
92+
**Default value**: `'section.mselect-list'`
93+
94+
### `mselectItemsWrapperClass`
95+
96+
Multiselect items wrapper class.
97+
98+
**Type**: String
99+
100+
**Default value**: `'mselect-items-wrapper'`
101+
102+
### `nextPageUrl`
103+
104+
The url of the controller or API which returns the JSON response.
105+
106+
```json
107+
{
108+
"success": true,
109+
"errorMessage": "",
110+
"result": [
111+
{
112+
"value": "1",
113+
"label": "Multi-select item label #1"
114+
},
115+
{
116+
"value": "2",
117+
"label": "Multi-select item label #2"
118+
}
119+
]
120+
}
121+
```
122+
123+
An example of the controller: [`<Magento_Tax_module_dir>/Controller/Adminhtml/Rule/AjaxLoadRates.php`][]
124+
125+
**Type**: String
126+
127+
**Default value**: `undefined`
86128

87129
### `searchInputClass`
88130

@@ -100,29 +142,92 @@ Class of the selected items counter.
100142

101143
**Default value**: `'admin__action-multiselect-search'`
102144

103-
### `currentPage`
145+
### `updateDelay`
104146

105-
Current page of multi-select items.
147+
The search field update delay.
106148

107-
**Type**: Integer
149+
**Type**: Integer, String
108150

109-
**Default value**: `1`
151+
**Default value**: `0`
110152

111-
### `lastAppendValue`
153+
## Methods
112154

113-
The value of the last added multi-select item.
155+
The Multiselect methods are the following:
114156

115-
**Type**: Integer, String
157+
- [appendOptions()](#appendoptions)
158+
- [clearMultiselectOptions()](#clearmultiselectoptions)
159+
- [getCurrentPage()](#getcurrentpage)
160+
- [getSearchCriteria()](#getsearchcriteria)
161+
- [isOptionsLoaded()](#isoptionsloaded)
162+
- [loadOptions()](#loadoptions)
163+
- [setCurrentPage()](#setcurrentpage)
116164

117-
**Default value**: `0`
165+
### `appendOptions`
118166

119-
### `updateDelay`
167+
The method appends multi-select items to the multi-select.
120168

121-
The search field update delay.
169+
Code example:
122170

123-
**Type**: Integer, String
171+
```javascript
172+
$('#multiselect').multiselect2('appendOptions', [{"value": "1", "label": "Label #1"}, {"value": "2", "label": "Label #2"}]);
173+
```
124174

125-
**Default value**: `0`
175+
### `clearMultiselectOptions`
176+
177+
The method removes all multi-select items.
178+
179+
Code example:
180+
181+
```javascript
182+
$('#multiselect').multiselect2('clearMultiselectOptions');
183+
```
184+
185+
### `getCurrentPage`
186+
187+
The method returns the number of the current page.
188+
189+
```javascript
190+
$('#multiselect').multiselect2('getCurrentPage');
191+
```
192+
193+
### `getSearchCriteria`
194+
195+
The method returns the trimmed value of the search input.
196+
197+
Code example:
198+
199+
```javascript
200+
$('#multiselect').multiselect2('getSearchCriteria');
201+
```
202+
203+
### `isOptionsLoaded`
204+
205+
The method checks if all multi-select items are already loaded.
206+
207+
```javascript
208+
$('#multiselect').multiselect2('isOptionsLoaded', [{"value": "2", "label": "Label #2"}]);
209+
```
210+
211+
This method returns `true` if multiple selection items are loaded, and it returns `false` if they are not loaded.
212+
213+
### `loadOptions`
214+
215+
The method loads the next page with multi-select items from [nextPageUrl](#nextpageurl) according to the [search criteria](#getsearchcriteria).
216+
The multi-select items from the Ajax response are appended to the multi-select.
217+
218+
Code example:
219+
220+
```javascript
221+
$('#multiselect').multiselect2('loadOptions');
222+
```
223+
224+
### `setCurrentPage`
225+
226+
The method configures the current page number.
227+
228+
```javascript
229+
$('#multiselect').multiselect2('setCurrentPage', 2);
230+
```
126231

127232
## Code sample
128233

@@ -156,3 +261,4 @@ You can now search for an option in the search bar and the **Add new value** but
156261
<!-- Link Definitions -->
157262
[lib/web/mage/multiselect.js]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/web/mage/multiselect.js
158263
[Initialize JavaScript]: {{page.baseurl}}/javascript-dev-guide/javascript/js_init.html
264+
[`<Magento_Tax_module_dir>/Controller/Adminhtml/Rule/AjaxLoadRates.php`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Tax/Controller/Adminhtml/Rule/AjaxLoadRates.php

0 commit comments

Comments
 (0)