inertia-bootstrap-forms 1.0.89 → 1.0.91
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/package.json
CHANGED
package/src/Select2Input.vue
CHANGED
|
@@ -13,7 +13,11 @@ export default defineComponent({
|
|
|
13
13
|
modelValue: '',
|
|
14
14
|
label: {
|
|
15
15
|
type: String,
|
|
16
|
-
default:
|
|
16
|
+
default: null,
|
|
17
|
+
},
|
|
18
|
+
key: {
|
|
19
|
+
type: String,
|
|
20
|
+
default: null,
|
|
17
21
|
},
|
|
18
22
|
placeholder: {
|
|
19
23
|
type: String,
|
|
@@ -125,17 +129,11 @@ export default defineComponent({
|
|
|
125
129
|
},
|
|
126
130
|
async setLoading() {
|
|
127
131
|
this.loading = true;
|
|
128
|
-
this.choices.clearChoices();
|
|
129
132
|
await this.choices.setChoices(
|
|
130
|
-
[
|
|
131
|
-
{
|
|
132
|
-
value: '',
|
|
133
|
-
label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...',
|
|
134
|
-
}
|
|
135
|
-
],
|
|
133
|
+
[{ value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true }],
|
|
136
134
|
'value',
|
|
137
135
|
'label',
|
|
138
|
-
true
|
|
136
|
+
true // replaceChoices
|
|
139
137
|
);
|
|
140
138
|
},
|
|
141
139
|
async doSearch(searchTerm) {
|
|
@@ -149,33 +147,30 @@ export default defineComponent({
|
|
|
149
147
|
this.searchController = new AbortController();
|
|
150
148
|
|
|
151
149
|
try {
|
|
152
|
-
const res = await fetch(this.search
|
|
150
|
+
const res = await fetch(this.search.url + '?query=' + encodeURIComponent(searchTerm), {
|
|
153
151
|
method: 'POST',
|
|
154
152
|
signal: this.searchController.signal,
|
|
155
153
|
});
|
|
156
154
|
const data = await res.json();
|
|
157
155
|
|
|
158
|
-
this.choices.clearChoices();
|
|
159
156
|
await this.choices.setChoices(
|
|
160
157
|
data.map(item => ({
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
value: item.id,
|
|
159
|
+
label: item.name || item.label || item.value,
|
|
163
160
|
})),
|
|
164
|
-
'
|
|
165
|
-
'
|
|
161
|
+
'value',
|
|
162
|
+
'label',
|
|
166
163
|
true
|
|
167
164
|
);
|
|
168
165
|
this.loading = false;
|
|
169
166
|
} catch (err) {
|
|
170
167
|
this.loading = false;
|
|
171
|
-
this.choices.clearChoices();
|
|
172
168
|
if (err.name !== 'AbortError') {
|
|
173
169
|
console.error(err);
|
|
170
|
+
await this.choices.setChoices([], 'value', 'label', true);
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
},
|
|
173
|
+
} },
|
|
179
174
|
mounted() {
|
|
180
175
|
if (this.locale === 'en' && document.dir === 'rtl') {
|
|
181
176
|
this.currentLocale = 'fa';
|
|
@@ -223,9 +218,9 @@ export default defineComponent({
|
|
|
223
218
|
:placeholder="placeholder"
|
|
224
219
|
ref="input">
|
|
225
220
|
<option
|
|
226
|
-
:value="(item
|
|
221
|
+
:value="((key ? item[key] : item?.name ?? item?.label ?? item?.value) ?? item)" v-for="(item, index) in options"
|
|
227
222
|
:selected="multiple ? (selectedValue || []).includes(item.id || item) : (item?.id?.toString() || item) === modelValue?.toString()">
|
|
228
|
-
{{ (label ? item[label] : item
|
|
223
|
+
{{ (label ? item[label] : item?.name ?? item?.label ?? item?.value) ?? item }}
|
|
229
224
|
</option>
|
|
230
225
|
</select>
|
|
231
226
|
</div>
|