inertia-bootstrap-forms 1.0.91 → 1.0.93
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-k3x7dkKf.js → index-BcwfWbci.js} +1081 -1071
- package/dist/{index-CoG5BgVi.js → index-DbRRjBpv.js} +1 -1
- 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 +36 -18
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,
|
|
@@ -101,6 +101,19 @@ export default defineComponent({
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
methods: {
|
|
104
|
+
getKeyFromItem(item) {
|
|
105
|
+
return ((this.key ? item[this.key] : item?.id ?? item?.name ?? item?.label ?? item?.value) ?? item)?.toString();
|
|
106
|
+
},
|
|
107
|
+
getLabelFromItem(item) {
|
|
108
|
+
return ((this.key ? item[this.key] : item?.id ?? item?.name ?? item?.label ?? item?.value) ?? item)
|
|
109
|
+
},
|
|
110
|
+
selected(item) {
|
|
111
|
+
if (this.multiple) {
|
|
112
|
+
return (this.selectedValue || []).includes(this.getKeyFromItem(item));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (this.getKeyFromItem(item)) === this.modelValue?.toString()
|
|
116
|
+
},
|
|
104
117
|
init() {
|
|
105
118
|
if (this.choices) {
|
|
106
119
|
this.destroy();
|
|
@@ -125,22 +138,28 @@ export default defineComponent({
|
|
|
125
138
|
this.choices.destroy();
|
|
126
139
|
},
|
|
127
140
|
searchHandle(event) {
|
|
128
|
-
this
|
|
141
|
+
this.$emit('search', event)
|
|
142
|
+
clearTimeout(this.searchDebounceTimer);
|
|
143
|
+
|
|
144
|
+
this.showLoading();
|
|
145
|
+
|
|
146
|
+
this.searchDebounceTimer = setTimeout(() => {
|
|
147
|
+
this.doSearch(event.detail.value);
|
|
148
|
+
}, 400);
|
|
129
149
|
},
|
|
130
|
-
async
|
|
150
|
+
async showLoading() {
|
|
131
151
|
this.loading = true;
|
|
132
152
|
await this.choices.setChoices(
|
|
133
|
-
[{
|
|
153
|
+
[{value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true}],
|
|
134
154
|
'value',
|
|
135
155
|
'label',
|
|
136
156
|
true // replaceChoices
|
|
137
157
|
);
|
|
138
158
|
},
|
|
139
159
|
async doSearch(searchTerm) {
|
|
160
|
+
this.$emit('searching', searchTerm)
|
|
140
161
|
if (!this.search?.url) return;
|
|
141
162
|
|
|
142
|
-
await this.setLoading();
|
|
143
|
-
|
|
144
163
|
if (this.searchController) {
|
|
145
164
|
this.searchController.abort();
|
|
146
165
|
}
|
|
@@ -155,8 +174,8 @@ export default defineComponent({
|
|
|
155
174
|
|
|
156
175
|
await this.choices.setChoices(
|
|
157
176
|
data.map(item => ({
|
|
158
|
-
value: item
|
|
159
|
-
label:
|
|
177
|
+
value: this.getKeyFromItem(item),
|
|
178
|
+
label: this.getLabelFromItem(item),
|
|
160
179
|
})),
|
|
161
180
|
'value',
|
|
162
181
|
'label',
|
|
@@ -164,13 +183,14 @@ export default defineComponent({
|
|
|
164
183
|
);
|
|
165
184
|
this.loading = false;
|
|
166
185
|
} catch (err) {
|
|
167
|
-
this.loading = false;
|
|
168
186
|
if (err.name !== 'AbortError') {
|
|
187
|
+
this.loading = false;
|
|
169
188
|
console.error(err);
|
|
170
189
|
await this.choices.setChoices([], 'value', 'label', true);
|
|
171
190
|
}
|
|
172
191
|
}
|
|
173
|
-
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
174
194
|
mounted() {
|
|
175
195
|
if (this.locale === 'en' && document.dir === 'rtl') {
|
|
176
196
|
this.currentLocale = 'fa';
|
|
@@ -185,6 +205,7 @@ export default defineComponent({
|
|
|
185
205
|
return {
|
|
186
206
|
choices: null,
|
|
187
207
|
loading: false,
|
|
208
|
+
searchDebounceTimer: null,
|
|
188
209
|
searchController: null,
|
|
189
210
|
currentLocale: this.locale,
|
|
190
211
|
localeTranslates: {
|
|
@@ -212,15 +233,12 @@ export default defineComponent({
|
|
|
212
233
|
v-model="modelValue"
|
|
213
234
|
class="form-control-select"
|
|
214
235
|
:class="{
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
:placeholder="placeholder"
|
|
236
|
+
'form-control-select--loading': loading,
|
|
237
|
+
'is-invalid': form.errors[name]
|
|
238
|
+
}"
|
|
219
239
|
ref="input">
|
|
220
|
-
<option
|
|
221
|
-
|
|
222
|
-
:selected="multiple ? (selectedValue || []).includes(item.id || item) : (item?.id?.toString() || item) === modelValue?.toString()">
|
|
223
|
-
{{ (label ? item[label] : item?.name ?? item?.label ?? item?.value) ?? item }}
|
|
240
|
+
<option :value="getKeyFromItem(item)" v-for="(item, index) in options" :selected="selected(item)">
|
|
241
|
+
{{ getLabelFromItem(item) }}
|
|
224
242
|
</option>
|
|
225
243
|
</select>
|
|
226
244
|
</div>
|