inertia-bootstrap-forms 1.0.90 → 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-BDrrKgQZ.js → index-FBOpgX9_.js} +1 -1
- package/dist/{index-BWLXdiIz.js → index-kihjHjls.js} +1079 -1080
- package/dist/inertia-bootstrap-forms.es.js +1 -1
- package/dist/inertia-bootstrap-forms.umd.js +8 -8
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Select2Input.vue +22 -24
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,61 +125,58 @@ 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
|
-
this.choices.clearChoices();
|
|
133
139
|
await this.choices.setChoices(
|
|
134
|
-
[
|
|
135
|
-
{
|
|
136
|
-
value: '',
|
|
137
|
-
label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...',
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
+
[{ value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true }],
|
|
140
141
|
'value',
|
|
141
142
|
'label',
|
|
142
|
-
true
|
|
143
|
+
true // replaceChoices
|
|
143
144
|
);
|
|
144
145
|
},
|
|
145
146
|
async doSearch(searchTerm) {
|
|
147
|
+
this.$emit('searching', searchTerm)
|
|
146
148
|
if (!this.search?.url) return;
|
|
147
149
|
|
|
148
|
-
await this.setLoading();
|
|
149
|
-
|
|
150
150
|
if (this.searchController) {
|
|
151
151
|
this.searchController.abort();
|
|
152
152
|
}
|
|
153
153
|
this.searchController = new AbortController();
|
|
154
154
|
|
|
155
155
|
try {
|
|
156
|
-
const res = await fetch(this.search
|
|
156
|
+
const res = await fetch(this.search.url + '?query=' + encodeURIComponent(searchTerm), {
|
|
157
157
|
method: 'POST',
|
|
158
158
|
signal: this.searchController.signal,
|
|
159
159
|
});
|
|
160
160
|
const data = await res.json();
|
|
161
161
|
|
|
162
|
-
this.choices.clearChoices();
|
|
163
162
|
await this.choices.setChoices(
|
|
164
163
|
data.map(item => ({
|
|
165
|
-
|
|
166
|
-
|
|
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,
|
|
167
166
|
})),
|
|
168
|
-
'
|
|
169
|
-
'
|
|
167
|
+
'value',
|
|
168
|
+
'label',
|
|
170
169
|
true
|
|
171
170
|
);
|
|
172
171
|
this.loading = false;
|
|
173
172
|
} catch (err) {
|
|
174
|
-
this.loading = false;
|
|
175
|
-
this.choices.clearChoices();
|
|
176
173
|
if (err.name !== 'AbortError') {
|
|
174
|
+
this.loading = false;
|
|
177
175
|
console.error(err);
|
|
176
|
+
await this.choices.setChoices([], 'value', 'label', true);
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
},
|
|
179
|
+
} },
|
|
183
180
|
mounted() {
|
|
184
181
|
if (this.locale === 'en' && document.dir === 'rtl') {
|
|
185
182
|
this.currentLocale = 'fa';
|
|
@@ -194,6 +191,7 @@ export default defineComponent({
|
|
|
194
191
|
return {
|
|
195
192
|
choices: null,
|
|
196
193
|
loading: false,
|
|
194
|
+
searchDebounceTimer: null,
|
|
197
195
|
searchController: null,
|
|
198
196
|
currentLocale: this.locale,
|
|
199
197
|
localeTranslates: {
|