inertia-bootstrap-forms 1.0.92 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.92",
3
+ "version": "1.0.93",
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",
@@ -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();
@@ -137,7 +150,7 @@ export default defineComponent({
137
150
  async showLoading() {
138
151
  this.loading = true;
139
152
  await this.choices.setChoices(
140
- [{ value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true }],
153
+ [{value: '', label: this.localeTranslates[this.currentLocale]['searchingPlaceholder'] || 'Searching...', disabled: true}],
141
154
  'value',
142
155
  'label',
143
156
  true // replaceChoices
@@ -161,8 +174,8 @@ export default defineComponent({
161
174
 
162
175
  await this.choices.setChoices(
163
176
  data.map(item => ({
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,
177
+ value: this.getKeyFromItem(item),
178
+ label: this.getLabelFromItem(item),
166
179
  })),
167
180
  'value',
168
181
  'label',
@@ -176,7 +189,8 @@ export default defineComponent({
176
189
  await this.choices.setChoices([], 'value', 'label', true);
177
190
  }
178
191
  }
179
- } },
192
+ }
193
+ },
180
194
  mounted() {
181
195
  if (this.locale === 'en' && document.dir === 'rtl') {
182
196
  this.currentLocale = 'fa';
@@ -219,15 +233,12 @@ export default defineComponent({
219
233
  v-model="modelValue"
220
234
  class="form-control-select"
221
235
  :class="{
222
- 'form-control-select--loading': loading,
223
- 'is-invalid': form.errors[name]
224
- }"
225
- :placeholder="placeholder"
236
+ 'form-control-select--loading': loading,
237
+ 'is-invalid': form.errors[name]
238
+ }"
226
239
  ref="input">
227
- <option
228
- :value="((key ? item[key] : item?.name ?? item?.label ?? item?.value) ?? item)" v-for="(item, index) in options"
229
- :selected="multiple ? (selectedValue || []).includes(item.id || item) : (item?.id?.toString() || item) === modelValue?.toString()">
230
- {{ (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) }}
231
242
  </option>
232
243
  </select>
233
244
  </div>