@lemonadejs/dropdown 5.8.1 → 5.8.2

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.
Files changed (2) hide show
  1. package/dist/index.js +29 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -739,7 +739,7 @@ if (!Modal && typeof (require) === 'function') {
739
739
  if (! self.isClosed() && self.autocomplete) {
740
740
 
741
741
  // Remote or normal search
742
- if (self.remote === true) {
742
+ if (self.remote === true && self.url) {
743
743
  // Clear existing timeout
744
744
  if (searchTimeout) {
745
745
  clearTimeout(searchTimeout);
@@ -1171,8 +1171,35 @@ if (!Modal && typeof (require) === 'function') {
1171
1171
  if (prop === 'value') {
1172
1172
  setValue(self.value);
1173
1173
  } else if (prop === 'data') {
1174
+ // Store current value before resetting data
1175
+ let currentValue = self.value;
1174
1176
  setData();
1175
- self.value = null;
1177
+
1178
+ // Only reset value if it's not in the new data
1179
+ if (currentValue !== null && currentValue !== undefined && currentValue !== '') {
1180
+ let valuesToCheck = Array.isArray(currentValue) ? currentValue : [currentValue];
1181
+
1182
+ // Filter to keep only values that exist in the new data
1183
+ let validValues = valuesToCheck.filter(v => {
1184
+ return self.data.some(item => {
1185
+ if (v === '' || item.value === '') {
1186
+ return v === item.value;
1187
+ }
1188
+ return v == item.value;
1189
+ });
1190
+ });
1191
+
1192
+ if (validValues.length === 0) {
1193
+ // No valid values remain, reset to null
1194
+ self.value = null;
1195
+ } else if (self.multiple) {
1196
+ // Multi-select: keep only valid values
1197
+ self.value = validValues;
1198
+ } else {
1199
+ // Single select: re-apply the value
1200
+ self.value = validValues[0];
1201
+ }
1202
+ }
1176
1203
  }
1177
1204
 
1178
1205
  if (typeof (lazyloading) === 'function') {
package/package.json CHANGED
@@ -15,9 +15,9 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "lemonadejs": "^5.3.6",
18
- "@lemonadejs/modal": "^5.8.0"
18
+ "@lemonadejs/modal": "^5.8.2"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "5.8.1"
22
+ "version": "5.8.2"
23
23
  }