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/index.d.ts CHANGED
@@ -328,6 +328,7 @@ export const Select2Input: DefineComponent<{
328
328
  {
329
329
  'update:modelValue': (data) => void,
330
330
  'search': (event) => void,
331
+ 'searching': (query) => void,
331
332
  'change': (file) => void,
332
333
  'selected': () => void,
333
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.91",
3
+ "version": "1.0.92",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "dist/inertia-bootstrap-forms.cjs.js",
6
6
  "module": "dist/inertia-bootstrap-forms.es.js",
@@ -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.doSearch(event.detail.value);
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 setLoading() {
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.id,
159
- label: item.name || item.label || item.value,
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: {