inertia-bootstrap-forms 1.0.91 → 1.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-CoG5BgVi.js → index-FBOpgX9_.js} +1 -1
- package/dist/{index-k3x7dkKf.js → index-kihjHjls.js} +12 -9
- package/dist/inertia-bootstrap-forms.es.js +1 -1
- package/dist/inertia-bootstrap-forms.umd.js +1 -1
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Select2Input.vue +15 -8
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/Select2Input.vue
CHANGED
|
@@ -4,7 +4,7 @@ import Choices from 'choices.js';
|
|
|
4
4
|
import {computed, defineComponent, inject} from "vue";
|
|
5
5
|
|
|
6
6
|
export default defineComponent({
|
|
7
|
-
emits: ['update:modelValue', 'search', 'change', 'selected'],
|
|
7
|
+
emits: ['update:modelValue', 'search', 'searching', 'change', 'selected'],
|
|
8
8
|
props: {
|
|
9
9
|
name: {
|
|
10
10
|
type: String,
|
|
@@ -125,9 +125,16 @@ export default defineComponent({
|
|
|
125
125
|
this.choices.destroy();
|
|
126
126
|
},
|
|
127
127
|
searchHandle(event) {
|
|
128
|
-
this
|
|
128
|
+
this.$emit('search', event)
|
|
129
|
+
clearTimeout(this.searchDebounceTimer);
|
|
130
|
+
|
|
131
|
+
this.showLoading();
|
|
132
|
+
|
|
133
|
+
this.searchDebounceTimer = setTimeout(() => {
|
|
134
|
+
this.doSearch(event.detail.value);
|
|
135
|
+
}, 400);
|
|
129
136
|
},
|
|
130
|
-
async
|
|
137
|
+
async showLoading() {
|
|
131
138
|
this.loading = true;
|
|
132
139
|
await this.choices.setChoices(
|
|
133
140
|
[{ value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true }],
|
|
@@ -137,10 +144,9 @@ export default defineComponent({
|
|
|
137
144
|
);
|
|
138
145
|
},
|
|
139
146
|
async doSearch(searchTerm) {
|
|
147
|
+
this.$emit('searching', searchTerm)
|
|
140
148
|
if (!this.search?.url) return;
|
|
141
149
|
|
|
142
|
-
await this.setLoading();
|
|
143
|
-
|
|
144
150
|
if (this.searchController) {
|
|
145
151
|
this.searchController.abort();
|
|
146
152
|
}
|
|
@@ -155,8 +161,8 @@ export default defineComponent({
|
|
|
155
161
|
|
|
156
162
|
await this.choices.setChoices(
|
|
157
163
|
data.map(item => ({
|
|
158
|
-
value: item.
|
|
159
|
-
label: item.name
|
|
164
|
+
value: ((this.key ? item[this.key] : item?.name ?? item?.label ?? item?.value) ?? item),
|
|
165
|
+
label: (this.label ? item[this.label] : item?.name ?? item?.label ?? item?.value) ?? item,
|
|
160
166
|
})),
|
|
161
167
|
'value',
|
|
162
168
|
'label',
|
|
@@ -164,8 +170,8 @@ export default defineComponent({
|
|
|
164
170
|
);
|
|
165
171
|
this.loading = false;
|
|
166
172
|
} catch (err) {
|
|
167
|
-
this.loading = false;
|
|
168
173
|
if (err.name !== 'AbortError') {
|
|
174
|
+
this.loading = false;
|
|
169
175
|
console.error(err);
|
|
170
176
|
await this.choices.setChoices([], 'value', 'label', true);
|
|
171
177
|
}
|
|
@@ -185,6 +191,7 @@ export default defineComponent({
|
|
|
185
191
|
return {
|
|
186
192
|
choices: null,
|
|
187
193
|
loading: false,
|
|
194
|
+
searchDebounceTimer: null,
|
|
188
195
|
searchController: null,
|
|
189
196
|
currentLocale: this.locale,
|
|
190
197
|
localeTranslates: {
|