Skip to content

Commit 2f23b48

Browse files
committed
Introduce ui-select filter with validation init values
1 parent 7fe1b9d commit 2f23b48

File tree

1 file changed

+82
-0
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid/filters/elements

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/element/ui-select',
8+
'jquery',
9+
'underscore'
10+
], function (Select, $, _) {
11+
'use strict';
12+
13+
return Select.extend({
14+
defaults: {
15+
bookmarkProvider: 'ns = ${ $.ns }, index = bookmarks',
16+
filterChipsProvider: 'componentType = filters, ns = ${ $.ns }',
17+
validationUrl: false,
18+
loadedOption: [],
19+
validationLoading: true,
20+
imports: {
21+
activeIndex: '${ $.bookmarkProvider }:activeIndex'
22+
},
23+
modules: {
24+
filterChips: '${ $.filterChipsProvider }'
25+
},
26+
listens: {
27+
activeIndex: 'validateInitialValue'
28+
}
29+
30+
},
31+
32+
/** @inheritdoc */
33+
initialize: function () {
34+
this._super();
35+
36+
this.validateInitialValue();
37+
38+
return this;
39+
},
40+
41+
/**
42+
* Validate initial value actually exists
43+
*/
44+
validateInitialValue: function () {
45+
if (!_.isEmpty(this.value())) {
46+
$.ajax({
47+
url: this.validationUrl,
48+
type: 'GET',
49+
dataType: 'json',
50+
context: this,
51+
data: {
52+
ids: this.value()
53+
},
54+
55+
/** @param {Object} response */
56+
success: function (response) {
57+
if (!_.isEmpty(response)) {
58+
this.options([]);
59+
this.success({
60+
options: response
61+
});
62+
}
63+
this.filterChips().updateActive();
64+
},
65+
66+
/** set empty array if error occurs */
67+
error: function () {
68+
this.options([]);
69+
},
70+
71+
/** stop loader */
72+
complete: function () {
73+
this.validationLoading(false);
74+
this.setCaption();
75+
}
76+
});
77+
} else {
78+
this.validationLoading(false);
79+
}
80+
}
81+
});
82+
});

0 commit comments

Comments
 (0)