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/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.90",
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,61 +125,58 @@ 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
- 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?.url + '?query=' + encodeURIComponent(searchTerm), {
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
- id: item.id,
166
- name: 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,
167
166
  })),
168
- 'id',
169
- 'name',
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: {