@keenthemes/ktui 1.0.24 → 1.0.26
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/dist/ktui.js +337 -18
- package/dist/ktui.min.js +1 -1
- package/dist/ktui.min.js.map +1 -1
- package/dist/styles.css +319 -11
- package/examples/datatable/checkbox-events-test.html +400 -0
- package/examples/datatable/credentials-test.html +423 -0
- package/examples/datatable/remote-checkbox-test.html +365 -0
- package/examples/modal/persistent-test.html +205 -0
- package/examples/select/dark-mode-test.html +93 -0
- package/examples/select/dropdowncontainer-test.html +111 -0
- package/examples/select/dynamic-methods.html +273 -0
- package/examples/select/formdata-remote-test.html +161 -0
- package/examples/select/modal-positioning-test.html +336 -0
- package/examples/select/remote-data-preselected.html +283 -0
- package/lib/cjs/components/datatable/datatable-checkbox.js +16 -3
- package/lib/cjs/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/cjs/components/datatable/datatable.js +3 -5
- package/lib/cjs/components/datatable/datatable.js.map +1 -1
- package/lib/cjs/components/image-input/image-input.js.map +1 -1
- package/lib/cjs/components/modal/modal.js +3 -1
- package/lib/cjs/components/modal/modal.js.map +1 -1
- package/lib/cjs/components/select/config.js +5 -0
- package/lib/cjs/components/select/config.js.map +1 -1
- package/lib/cjs/components/select/dropdown.js +25 -2
- package/lib/cjs/components/select/dropdown.js.map +1 -1
- package/lib/cjs/components/select/select.js +285 -7
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/cjs/components/select/templates.js.map +1 -1
- package/lib/esm/components/datatable/datatable-checkbox.js +16 -3
- package/lib/esm/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/esm/components/datatable/datatable.js +3 -5
- package/lib/esm/components/datatable/datatable.js.map +1 -1
- package/lib/esm/components/image-input/image-input.js.map +1 -1
- package/lib/esm/components/modal/modal.js +3 -1
- package/lib/esm/components/modal/modal.js.map +1 -1
- package/lib/esm/components/select/config.js +5 -0
- package/lib/esm/components/select/config.js.map +1 -1
- package/lib/esm/components/select/dropdown.js +25 -2
- package/lib/esm/components/select/dropdown.js.map +1 -1
- package/lib/esm/components/select/select.js +285 -7
- package/lib/esm/components/select/select.js.map +1 -1
- package/lib/esm/components/select/templates.js.map +1 -1
- package/package.json +1 -1
- package/src/components/datatable/datatable-checkbox.ts +18 -3
- package/src/components/datatable/datatable.ts +3 -0
- package/src/components/datatable/types.ts +1 -0
- package/src/components/image-input/image-input.ts +12 -15
- package/src/components/modal/modal.ts +5 -1
- package/src/components/select/config.ts +6 -0
- package/src/components/select/dropdown.ts +32 -3
- package/src/components/select/select.css +4 -4
- package/src/components/select/select.ts +350 -9
- package/src/components/select/templates.ts +2 -1
package/dist/ktui.js
CHANGED
|
@@ -6993,8 +6993,11 @@ function createCheckboxHandler(element, config, fireEvent) {
|
|
|
6993
6993
|
return;
|
|
6994
6994
|
var value = input.value;
|
|
6995
6995
|
var selectedRows = getSelectedRows();
|
|
6996
|
-
|
|
6997
|
-
|
|
6996
|
+
var wasChecked = selectedRows.includes(value);
|
|
6997
|
+
var isNowChecked = input.checked;
|
|
6998
|
+
// Update state first
|
|
6999
|
+
if (isNowChecked) {
|
|
7000
|
+
if (!wasChecked)
|
|
6998
7001
|
selectedRows.push(value);
|
|
6999
7002
|
}
|
|
7000
7003
|
else {
|
|
@@ -7002,14 +7005,24 @@ function createCheckboxHandler(element, config, fireEvent) {
|
|
|
7002
7005
|
}
|
|
7003
7006
|
setSelectedRows(selectedRows);
|
|
7004
7007
|
updateHeaderCheckboxState();
|
|
7008
|
+
// Fire specific checked/unchecked events after state is updated
|
|
7009
|
+
if (isNowChecked && !wasChecked) {
|
|
7010
|
+
fireEvent('checked');
|
|
7011
|
+
}
|
|
7012
|
+
else if (!isNowChecked && wasChecked) {
|
|
7013
|
+
fireEvent('unchecked');
|
|
7014
|
+
}
|
|
7015
|
+
// Always fire changed event for backward compatibility
|
|
7005
7016
|
fireEvent('changed');
|
|
7006
7017
|
}
|
|
7007
7018
|
// When the header checkbox is toggled
|
|
7008
7019
|
function checkboxToggle(event) {
|
|
7009
7020
|
var checked = !isChecked();
|
|
7021
|
+
// Update state first, then fire events
|
|
7022
|
+
change(checked);
|
|
7023
|
+
// Fire checked/unchecked events after state is updated
|
|
7010
7024
|
var eventType = checked ? 'checked' : 'unchecked';
|
|
7011
7025
|
fireEvent(eventType);
|
|
7012
|
-
change(checked);
|
|
7013
7026
|
}
|
|
7014
7027
|
// Change all visible checkboxes and update selectedRows
|
|
7015
7028
|
function change(checked) {
|
|
@@ -8405,11 +8418,9 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
8405
8418
|
apiEndpointWithQueryParams.search = queryParams.toString();
|
|
8406
8419
|
this._config.apiEndpoint = apiEndpointWithQueryParams.toString();
|
|
8407
8420
|
}
|
|
8408
|
-
return [2 /*return*/, fetch(this._config.apiEndpoint, {
|
|
8409
|
-
|
|
8410
|
-
|
|
8411
|
-
headers: this._config.requestHeaders,
|
|
8412
|
-
}).catch(function (error) {
|
|
8421
|
+
return [2 /*return*/, fetch(this._config.apiEndpoint, __assign({ method: requestMethod, body: requestBody, headers: this._config.requestHeaders }, (this._config.requestCredentials && {
|
|
8422
|
+
credentials: this._config.requestCredentials,
|
|
8423
|
+
}))).catch(function (error) {
|
|
8413
8424
|
// Trigger an error event
|
|
8414
8425
|
_this._fireEvent('error', { error: error });
|
|
8415
8426
|
_this._dispatchEvent('error', { error: error });
|
|
@@ -9243,7 +9254,9 @@ var KTModal = /** @class */ (function (_super) {
|
|
|
9243
9254
|
this._element.addEventListener('click', function (event) {
|
|
9244
9255
|
if (_this._element !== event.target)
|
|
9245
9256
|
return;
|
|
9246
|
-
if
|
|
9257
|
+
// Only hide if both backdropStatic is false AND persistent is false
|
|
9258
|
+
if (_this._getOption('backdropStatic') === false &&
|
|
9259
|
+
utils_1.default.stringToBoolean(_this._getOption('persistent')) === false) {
|
|
9247
9260
|
_this._hide();
|
|
9248
9261
|
}
|
|
9249
9262
|
});
|
|
@@ -9632,6 +9645,26 @@ var KTSelectDropdown = /** @class */ (function (_super) {
|
|
|
9632
9645
|
this._dropdownElement.style.width = "".concat(toggleWidth, "px");
|
|
9633
9646
|
}
|
|
9634
9647
|
};
|
|
9648
|
+
/**
|
|
9649
|
+
* Detect if the select is inside a modal container
|
|
9650
|
+
* @returns The modal element if found, null otherwise
|
|
9651
|
+
*/
|
|
9652
|
+
KTSelectDropdown.prototype._getModalContainer = function () {
|
|
9653
|
+
return this._element.closest('[data-kt-modal], .kt-modal, .kt-modal-center');
|
|
9654
|
+
};
|
|
9655
|
+
/**
|
|
9656
|
+
* Get the appropriate positioning strategy based on context
|
|
9657
|
+
* @returns 'fixed' if inside modal, 'absolute' otherwise
|
|
9658
|
+
*/
|
|
9659
|
+
KTSelectDropdown.prototype._getPositioningStrategy = function () {
|
|
9660
|
+
// Check if config explicitly sets strategy
|
|
9661
|
+
if (this._config.dropdownStrategy) {
|
|
9662
|
+
return this._config.dropdownStrategy;
|
|
9663
|
+
}
|
|
9664
|
+
// Use fixed positioning if inside a modal (to handle transform-based centering)
|
|
9665
|
+
var modalParent = this._getModalContainer();
|
|
9666
|
+
return modalParent ? 'fixed' : 'absolute';
|
|
9667
|
+
};
|
|
9635
9668
|
/**
|
|
9636
9669
|
* Initialize the Popper instance for dropdown positioning
|
|
9637
9670
|
*/
|
|
@@ -9642,9 +9675,12 @@ var KTSelectDropdown = /** @class */ (function (_super) {
|
|
|
9642
9675
|
var offsetValue = '0, 5';
|
|
9643
9676
|
// Get configuration options
|
|
9644
9677
|
var placement = this._config.dropdownPlacement || 'bottom-start';
|
|
9645
|
-
var strategy = this.
|
|
9678
|
+
var strategy = this._getPositioningStrategy();
|
|
9646
9679
|
var preventOverflow = this._config.dropdownPreventOverflow !== false;
|
|
9647
9680
|
var flip = this._config.dropdownFlip !== false;
|
|
9681
|
+
// Detect modal container for boundary
|
|
9682
|
+
var modalParent = this._getModalContainer();
|
|
9683
|
+
var boundary = modalParent || 'clippingParents';
|
|
9648
9684
|
// Create new popper instance
|
|
9649
9685
|
this._popperInstance = (0, core_1.createPopper)(this._toggleElement, this._dropdownElement, {
|
|
9650
9686
|
placement: placement,
|
|
@@ -9659,7 +9695,7 @@ var KTSelectDropdown = /** @class */ (function (_super) {
|
|
|
9659
9695
|
{
|
|
9660
9696
|
name: 'preventOverflow',
|
|
9661
9697
|
options: {
|
|
9662
|
-
boundary:
|
|
9698
|
+
boundary: boundary,
|
|
9663
9699
|
altAxis: preventOverflow,
|
|
9664
9700
|
},
|
|
9665
9701
|
},
|
|
@@ -11660,6 +11696,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11660
11696
|
_this._selectAllButtonToggle = null;
|
|
11661
11697
|
_this._typeToSearchBuffer = new utils_1.TypeToSearchBuffer();
|
|
11662
11698
|
_this._mutationObserver = null;
|
|
11699
|
+
_this._preSelectedValues = [];
|
|
11663
11700
|
// Search debounce timeout
|
|
11664
11701
|
_this._searchDebounceTimeout = null;
|
|
11665
11702
|
// Store original options HTML for restoring after search
|
|
@@ -11773,6 +11810,14 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11773
11810
|
* Clear existing options from the select element
|
|
11774
11811
|
*/
|
|
11775
11812
|
KTSelect.prototype._clearExistingOptions = function () {
|
|
11813
|
+
// Capture pre-selected values before clearing (for remote data)
|
|
11814
|
+
var selectedOptions = Array.from(this._element.querySelectorAll('option[selected]:not([value=""])'));
|
|
11815
|
+
if (selectedOptions.length > 0) {
|
|
11816
|
+
this._preSelectedValues = selectedOptions.map(function (opt) { return opt.value; });
|
|
11817
|
+
if (this._config.debug) {
|
|
11818
|
+
console.log('Captured pre-selected values before clearing:', this._preSelectedValues);
|
|
11819
|
+
}
|
|
11820
|
+
}
|
|
11776
11821
|
// Keep only the empty/placeholder option and remove the rest
|
|
11777
11822
|
var options = Array.from(this._element.querySelectorAll('option:not([value=""])'));
|
|
11778
11823
|
options.forEach(function (option) { return option.remove(); });
|
|
@@ -11829,7 +11874,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11829
11874
|
// Batch append all options at once
|
|
11830
11875
|
optionsContainer.appendChild(fragment);
|
|
11831
11876
|
// Update options NodeList
|
|
11832
|
-
this._options = this.
|
|
11877
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
11833
11878
|
if (this._config.debug) {
|
|
11834
11879
|
console.log("Rendered ".concat(optionsData.length, " options in dropdown"));
|
|
11835
11880
|
}
|
|
@@ -11849,6 +11894,47 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11849
11894
|
KTSelect.prototype._completeRemoteSetup = function () {
|
|
11850
11895
|
// Initialize options
|
|
11851
11896
|
this._preSelectOptions(this._element);
|
|
11897
|
+
// Apply pre-selected values captured before remote data was loaded
|
|
11898
|
+
if (this._preSelectedValues.length > 0) {
|
|
11899
|
+
if (this._config.debug) {
|
|
11900
|
+
console.log('Applying pre-selected values after remote data loaded:', this._preSelectedValues);
|
|
11901
|
+
}
|
|
11902
|
+
// Get all available option values from the loaded remote data
|
|
11903
|
+
var availableValues_1 = Array.from(this._element.querySelectorAll('option')).map(function (opt) { return opt.value; });
|
|
11904
|
+
// Filter pre-selected values to only those that exist in remote data
|
|
11905
|
+
var validPreSelectedValues = this._preSelectedValues.filter(function (value) {
|
|
11906
|
+
return availableValues_1.includes(value);
|
|
11907
|
+
});
|
|
11908
|
+
if (validPreSelectedValues.length > 0) {
|
|
11909
|
+
// For single-select mode, only use the first value
|
|
11910
|
+
var valuesToSelect = this._config.multiple
|
|
11911
|
+
? validPreSelectedValues
|
|
11912
|
+
: [validPreSelectedValues[0]];
|
|
11913
|
+
if (this._config.debug) {
|
|
11914
|
+
console.log('Selecting matched values:', valuesToSelect);
|
|
11915
|
+
}
|
|
11916
|
+
// Get any existing selections from _preSelectOptions (e.g., data-kt-select-pre-selected)
|
|
11917
|
+
var existingSelections = this._state.getSelectedOptions();
|
|
11918
|
+
// Merge existing selections with native pre-selected values (no duplicates)
|
|
11919
|
+
var allSelections_1 = this._config.multiple
|
|
11920
|
+
? Array.from(new Set(__spreadArray(__spreadArray([], existingSelections, true), valuesToSelect, true)))
|
|
11921
|
+
: valuesToSelect;
|
|
11922
|
+
// Set all selections at once to avoid toggling issues
|
|
11923
|
+
this._state.setSelectedOptions(allSelections_1);
|
|
11924
|
+
// Update the native select element to match
|
|
11925
|
+
Array.from(this._element.querySelectorAll('option')).forEach(function (opt) {
|
|
11926
|
+
opt.selected = allSelections_1.includes(opt.value);
|
|
11927
|
+
});
|
|
11928
|
+
// Update the visual display
|
|
11929
|
+
this.updateSelectedOptionDisplay();
|
|
11930
|
+
this._updateSelectedOptionClass();
|
|
11931
|
+
}
|
|
11932
|
+
else if (this._config.debug) {
|
|
11933
|
+
console.log('None of the pre-selected values matched remote data:', this._preSelectedValues);
|
|
11934
|
+
}
|
|
11935
|
+
// Clear the pre-selected values array after processing
|
|
11936
|
+
this._preSelectedValues = [];
|
|
11937
|
+
}
|
|
11852
11938
|
// Apply disabled state if needed
|
|
11853
11939
|
this._applyInitialDisabledState();
|
|
11854
11940
|
// Initialize search if enabled
|
|
@@ -12032,7 +12118,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12032
12118
|
}
|
|
12033
12119
|
});
|
|
12034
12120
|
// Update options NodeList to include the new options
|
|
12035
|
-
this._options = this.
|
|
12121
|
+
this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12036
12122
|
if (this._config.debug)
|
|
12037
12123
|
console.log("Added ".concat(newItems.length, " more options to dropdown"));
|
|
12038
12124
|
};
|
|
@@ -12176,7 +12262,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12176
12262
|
this._selectAllButton = this._wrapperElement.querySelector('[data-kt-select-select-all]');
|
|
12177
12263
|
// Cache the options container for performance
|
|
12178
12264
|
this._optionsContainer = this._dropdownContentElement.querySelector('[data-kt-select-options]');
|
|
12179
|
-
this._options = this.
|
|
12265
|
+
this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12180
12266
|
};
|
|
12181
12267
|
/**
|
|
12182
12268
|
* Attach all event listeners to elements
|
|
@@ -12483,6 +12569,22 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12483
12569
|
selectedOptions: this.getSelectedOptions(),
|
|
12484
12570
|
});
|
|
12485
12571
|
};
|
|
12572
|
+
/**
|
|
12573
|
+
* Sync native select value attribute for FormData support
|
|
12574
|
+
*/
|
|
12575
|
+
KTSelect.prototype._syncNativeSelectValue = function () {
|
|
12576
|
+
var selectedOptions = this.getSelectedOptions();
|
|
12577
|
+
if (this._config.multiple) {
|
|
12578
|
+
// For multiple select, the selected options are marked via option.selected
|
|
12579
|
+
// The native select's value property will return the first selected option's value
|
|
12580
|
+
// FormData will include all selected values automatically
|
|
12581
|
+
}
|
|
12582
|
+
else {
|
|
12583
|
+
// For single select, set the value attribute explicitly
|
|
12584
|
+
var selectedValue = selectedOptions.length > 0 ? selectedOptions[0] : '';
|
|
12585
|
+
this._element.value = selectedValue;
|
|
12586
|
+
}
|
|
12587
|
+
};
|
|
12486
12588
|
/**
|
|
12487
12589
|
* Update selected option display value
|
|
12488
12590
|
*/
|
|
@@ -12490,6 +12592,8 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12490
12592
|
var selectedOptions = this.getSelectedOptions();
|
|
12491
12593
|
var tagsEnabled = this._config.tags && this._tagsModule;
|
|
12492
12594
|
var valueDisplayEl = this.getValueDisplayElement();
|
|
12595
|
+
// Sync native select value for FormData support
|
|
12596
|
+
this._syncNativeSelectValue();
|
|
12493
12597
|
if (tagsEnabled) {
|
|
12494
12598
|
// Tags module will render tags if selectedOptions > 0, or clear them if selectedOptions === 0.
|
|
12495
12599
|
this._tagsModule.updateTagsDisplay(selectedOptions);
|
|
@@ -12546,7 +12650,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12546
12650
|
*/
|
|
12547
12651
|
KTSelect.prototype._updateSelectedOptionClass = function () {
|
|
12548
12652
|
var _this = this;
|
|
12549
|
-
var allOptions = this.
|
|
12653
|
+
var allOptions = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12550
12654
|
var selectedValues = this._state.getSelectedOptions();
|
|
12551
12655
|
var maxReached = typeof this._config.maxSelections === 'number' &&
|
|
12552
12656
|
selectedValues.length >= this._config.maxSelections;
|
|
@@ -12591,6 +12695,8 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12591
12695
|
Array.from(this._element.querySelectorAll('option')).forEach(function (opt) {
|
|
12592
12696
|
opt.selected = false;
|
|
12593
12697
|
});
|
|
12698
|
+
// Clear native select value
|
|
12699
|
+
this._element.value = '';
|
|
12594
12700
|
this.updateSelectedOptionDisplay();
|
|
12595
12701
|
this._updateSelectedOptionClass();
|
|
12596
12702
|
// Update select all button state
|
|
@@ -12759,7 +12865,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12759
12865
|
*/
|
|
12760
12866
|
KTSelect.prototype.showAllOptions = function () {
|
|
12761
12867
|
// Get all options in the dropdown
|
|
12762
|
-
var options = Array.from(this.
|
|
12868
|
+
var options = Array.from(this._dropdownContentElement.querySelectorAll("[data-kt-select-option]"));
|
|
12763
12869
|
// Show all options by removing the hidden class and any inline styles
|
|
12764
12870
|
options.forEach(function (option) {
|
|
12765
12871
|
var _a;
|
|
@@ -12906,6 +13012,214 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12906
13012
|
// Call parent dispose to clean up data
|
|
12907
13013
|
_super.prototype.dispose.call(this);
|
|
12908
13014
|
};
|
|
13015
|
+
/**
|
|
13016
|
+
* ========================================================================
|
|
13017
|
+
* DYNAMIC CONTROL METHODS
|
|
13018
|
+
* ========================================================================
|
|
13019
|
+
*/
|
|
13020
|
+
/**
|
|
13021
|
+
* Programmatically enable the select component
|
|
13022
|
+
* @public
|
|
13023
|
+
*/
|
|
13024
|
+
KTSelect.prototype.enable = function () {
|
|
13025
|
+
// Update config state
|
|
13026
|
+
this._config.disabled = false;
|
|
13027
|
+
// Remove disabled attribute from native select
|
|
13028
|
+
this._element.removeAttribute('disabled');
|
|
13029
|
+
this._element.classList.remove('disabled');
|
|
13030
|
+
// Remove disabled state from wrapper and display elements
|
|
13031
|
+
if (this._wrapperElement) {
|
|
13032
|
+
this._wrapperElement.classList.remove('disabled');
|
|
13033
|
+
}
|
|
13034
|
+
if (this._displayElement) {
|
|
13035
|
+
this._displayElement.removeAttribute('aria-disabled');
|
|
13036
|
+
}
|
|
13037
|
+
// Dispatch enabled event
|
|
13038
|
+
this._dispatchEvent('enabled');
|
|
13039
|
+
this._fireEvent('enabled');
|
|
13040
|
+
};
|
|
13041
|
+
/**
|
|
13042
|
+
* Programmatically disable the select component
|
|
13043
|
+
* @public
|
|
13044
|
+
*/
|
|
13045
|
+
KTSelect.prototype.disable = function () {
|
|
13046
|
+
// Update config state
|
|
13047
|
+
this._config.disabled = true;
|
|
13048
|
+
// Close dropdown if currently open
|
|
13049
|
+
if (this._dropdownIsOpen) {
|
|
13050
|
+
this.closeDropdown();
|
|
13051
|
+
}
|
|
13052
|
+
// Add disabled attribute to native select
|
|
13053
|
+
this._element.setAttribute('disabled', 'disabled');
|
|
13054
|
+
this._element.classList.add('disabled');
|
|
13055
|
+
// Add disabled state to wrapper and display elements
|
|
13056
|
+
if (this._wrapperElement) {
|
|
13057
|
+
this._wrapperElement.classList.add('disabled');
|
|
13058
|
+
}
|
|
13059
|
+
if (this._displayElement) {
|
|
13060
|
+
this._displayElement.setAttribute('aria-disabled', 'true');
|
|
13061
|
+
}
|
|
13062
|
+
// Dispatch disabled event
|
|
13063
|
+
this._dispatchEvent('disabled');
|
|
13064
|
+
this._fireEvent('disabled');
|
|
13065
|
+
};
|
|
13066
|
+
/**
|
|
13067
|
+
* Update the dropdown to sync with native select element changes
|
|
13068
|
+
* For remote selects, refetches data from the server
|
|
13069
|
+
* Optionally accepts new options to replace existing ones (static selects only)
|
|
13070
|
+
* @param newOptions Optional array of new options [{value, text}, ...]
|
|
13071
|
+
* @public
|
|
13072
|
+
*/
|
|
13073
|
+
KTSelect.prototype.update = function (newOptions) {
|
|
13074
|
+
var _this = this;
|
|
13075
|
+
// For remote selects, refetch data
|
|
13076
|
+
if (this._config.remote && this._remoteModule) {
|
|
13077
|
+
this._remoteModule
|
|
13078
|
+
.fetchData()
|
|
13079
|
+
.then(function (items) {
|
|
13080
|
+
// Clear existing options
|
|
13081
|
+
_this._clearExistingOptions();
|
|
13082
|
+
// Add new options from remote data
|
|
13083
|
+
items.forEach(function (item) {
|
|
13084
|
+
var option = document.createElement('option');
|
|
13085
|
+
option.value = item.id;
|
|
13086
|
+
option.textContent = item.title;
|
|
13087
|
+
if (item.disabled)
|
|
13088
|
+
option.disabled = true;
|
|
13089
|
+
_this._element.appendChild(option);
|
|
13090
|
+
});
|
|
13091
|
+
// Rebuild dropdown
|
|
13092
|
+
_this._rebuildOptionsFromNative();
|
|
13093
|
+
// Dispatch updated event
|
|
13094
|
+
_this._dispatchEvent('updated');
|
|
13095
|
+
_this._fireEvent('updated');
|
|
13096
|
+
})
|
|
13097
|
+
.catch(function (error) {
|
|
13098
|
+
console.error('Error updating remote data:', error);
|
|
13099
|
+
_this._dispatchEvent('updateError');
|
|
13100
|
+
_this._fireEvent('updateError');
|
|
13101
|
+
});
|
|
13102
|
+
}
|
|
13103
|
+
else {
|
|
13104
|
+
// For static selects, handle new options
|
|
13105
|
+
if (newOptions) {
|
|
13106
|
+
// Clear existing options except placeholder
|
|
13107
|
+
this._clearExistingOptions();
|
|
13108
|
+
// Add new options to native select
|
|
13109
|
+
newOptions.forEach(function (opt) {
|
|
13110
|
+
var option = document.createElement('option');
|
|
13111
|
+
option.value = opt.value;
|
|
13112
|
+
option.textContent = opt.text;
|
|
13113
|
+
_this._element.appendChild(option);
|
|
13114
|
+
});
|
|
13115
|
+
}
|
|
13116
|
+
// Rebuild dropdown from native select
|
|
13117
|
+
this._rebuildOptionsFromNative();
|
|
13118
|
+
// Dispatch updated event
|
|
13119
|
+
this._dispatchEvent('updated');
|
|
13120
|
+
this._fireEvent('updated');
|
|
13121
|
+
}
|
|
13122
|
+
};
|
|
13123
|
+
/**
|
|
13124
|
+
* Reload remote data and rebuild the dropdown
|
|
13125
|
+
* Only works with remote data enabled
|
|
13126
|
+
* @returns Promise that resolves when reload completes
|
|
13127
|
+
* @public
|
|
13128
|
+
*/
|
|
13129
|
+
KTSelect.prototype.reload = function () {
|
|
13130
|
+
var _this = this;
|
|
13131
|
+
// Guard clause: only works with remote data
|
|
13132
|
+
if (!this._config.remote || !this._remoteModule) {
|
|
13133
|
+
console.warn('reload() only works with remote data enabled');
|
|
13134
|
+
return Promise.resolve();
|
|
13135
|
+
}
|
|
13136
|
+
// Dispatch reload start event
|
|
13137
|
+
this._dispatchEvent('reloadStart');
|
|
13138
|
+
this._fireEvent('reloadStart');
|
|
13139
|
+
// Fetch fresh remote data
|
|
13140
|
+
return this._remoteModule
|
|
13141
|
+
.fetchData()
|
|
13142
|
+
.then(function (items) {
|
|
13143
|
+
// Clear existing options
|
|
13144
|
+
_this._clearExistingOptions();
|
|
13145
|
+
// Update state with new items
|
|
13146
|
+
return _this._state.setItems(items).then(function () {
|
|
13147
|
+
// Generate new options HTML
|
|
13148
|
+
_this._generateOptionsHtml(_this._element);
|
|
13149
|
+
// Update the dropdown
|
|
13150
|
+
_this._updateDropdownWithNewOptions();
|
|
13151
|
+
// Sync selection state from native select
|
|
13152
|
+
_this._syncSelectionFromNative();
|
|
13153
|
+
// Update visual display
|
|
13154
|
+
_this.updateSelectedOptionDisplay();
|
|
13155
|
+
_this._updateSelectedOptionClass();
|
|
13156
|
+
// Update select all button state if applicable
|
|
13157
|
+
if (_this._config.multiple && _this._config.enableSelectAll) {
|
|
13158
|
+
_this.updateSelectAllButtonState();
|
|
13159
|
+
}
|
|
13160
|
+
// Dispatch reload complete event
|
|
13161
|
+
_this._dispatchEvent('reloadComplete');
|
|
13162
|
+
_this._fireEvent('reloadComplete');
|
|
13163
|
+
});
|
|
13164
|
+
})
|
|
13165
|
+
.catch(function (error) {
|
|
13166
|
+
console.error('Error reloading remote data:', error);
|
|
13167
|
+
// Dispatch reload error event with error details
|
|
13168
|
+
_this._dispatchEvent('reloadError', { error: error });
|
|
13169
|
+
_this._fireEvent('reloadError', { error: error });
|
|
13170
|
+
// Re-throw error so caller can handle it
|
|
13171
|
+
throw error;
|
|
13172
|
+
});
|
|
13173
|
+
};
|
|
13174
|
+
/**
|
|
13175
|
+
* Refresh the visual display and state without rebuilding options
|
|
13176
|
+
* For remote selects, refetches data from the server
|
|
13177
|
+
* @public
|
|
13178
|
+
*/
|
|
13179
|
+
KTSelect.prototype.refresh = function () {
|
|
13180
|
+
var _this = this;
|
|
13181
|
+
// For remote selects, refetch data
|
|
13182
|
+
if (this._config.remote && this._remoteModule) {
|
|
13183
|
+
this._remoteModule
|
|
13184
|
+
.fetchData()
|
|
13185
|
+
.then(function (items) {
|
|
13186
|
+
// Clear existing options
|
|
13187
|
+
_this._clearExistingOptions();
|
|
13188
|
+
// Add new options
|
|
13189
|
+
items.forEach(function (item) {
|
|
13190
|
+
var option = document.createElement('option');
|
|
13191
|
+
option.value = item.id;
|
|
13192
|
+
option.textContent = item.title;
|
|
13193
|
+
if (item.disabled)
|
|
13194
|
+
option.disabled = true;
|
|
13195
|
+
_this._element.appendChild(option);
|
|
13196
|
+
});
|
|
13197
|
+
// Rebuild dropdown
|
|
13198
|
+
_this._rebuildOptionsFromNative();
|
|
13199
|
+
// Sync selection state
|
|
13200
|
+
_this._syncSelectionFromNative();
|
|
13201
|
+
// Reapply ARIA attributes
|
|
13202
|
+
_this._setAriaAttributes();
|
|
13203
|
+
// Dispatch refreshed event
|
|
13204
|
+
_this._dispatchEvent('refreshed');
|
|
13205
|
+
_this._fireEvent('refreshed');
|
|
13206
|
+
})
|
|
13207
|
+
.catch(function (error) {
|
|
13208
|
+
console.error('Error refreshing remote data:', error);
|
|
13209
|
+
_this._dispatchEvent('refreshError');
|
|
13210
|
+
_this._fireEvent('refreshError');
|
|
13211
|
+
});
|
|
13212
|
+
}
|
|
13213
|
+
else {
|
|
13214
|
+
// For static selects, just sync visual state
|
|
13215
|
+
this._syncSelectionFromNative();
|
|
13216
|
+
// Reapply ARIA attributes
|
|
13217
|
+
this._setAriaAttributes();
|
|
13218
|
+
// Dispatch refreshed event
|
|
13219
|
+
this._dispatchEvent('refreshed');
|
|
13220
|
+
this._fireEvent('refreshed');
|
|
13221
|
+
}
|
|
13222
|
+
};
|
|
12909
13223
|
/**
|
|
12910
13224
|
* ========================================================================
|
|
12911
13225
|
* STATIC METHODS
|
|
@@ -13039,7 +13353,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
13039
13353
|
// Restore original options
|
|
13040
13354
|
optionsContainer.innerHTML = this._originalOptionsHtml;
|
|
13041
13355
|
// Update options NodeList
|
|
13042
|
-
this._options = this.
|
|
13356
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
13043
13357
|
// Refresh search module
|
|
13044
13358
|
if (this._searchModule) {
|
|
13045
13359
|
this._searchModule.refreshAfterSearch();
|
|
@@ -13344,7 +13658,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
13344
13658
|
optionsContainer_1.appendChild(renderedOption);
|
|
13345
13659
|
});
|
|
13346
13660
|
// Update internal references
|
|
13347
|
-
this._options = this.
|
|
13661
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
13348
13662
|
}
|
|
13349
13663
|
}
|
|
13350
13664
|
// Sync selection after rebuilding
|
|
@@ -18308,6 +18622,11 @@ var KTSelectState = /** @class */ (function () {
|
|
|
18308
18622
|
return this._config;
|
|
18309
18623
|
};
|
|
18310
18624
|
KTSelectState.prototype.setSelectedOptions = function (value) {
|
|
18625
|
+
// Handle empty array case first to prevent undefined elements
|
|
18626
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
18627
|
+
this._selectedOptions = [];
|
|
18628
|
+
return;
|
|
18629
|
+
}
|
|
18311
18630
|
if (this._config.multiple &&
|
|
18312
18631
|
typeof value === 'string' &&
|
|
18313
18632
|
!this._selectedOptions.includes(value)) {
|