[FIX] 補強公司篩選下拉選單的 AJAX 後選中狀態顯示
1. 為 option 元素補上 server-side selected 屬性,確保 Preline autoInit 重建時能正確讀取已選中的公司選項。 2. 在 fetchTabContent AJAX 完成後,主動呼叫 HSSelect.setValue() 強制同步下拉選單的顯示文字,消除選中狀態消失的視覺問題。
This commit is contained in:
parent
90192dbed9
commit
18162dfa4c
@ -234,7 +234,7 @@
|
||||
@change="$el.closest('form').dispatchEvent(new Event('submit'))">
|
||||
<x-searchable-select name="filter_company_id" :placeholder="__('All Companies')" :selected="request('filter_company_id')">
|
||||
@foreach($allCompanies as $c)
|
||||
<option value="{{ $c->id }}" data-title="{{ $c->name }}">{{ $c->name }}</option>
|
||||
<option value="{{ $c->id }}" data-title="{{ $c->name }}" {{ (string)request('filter_company_id') === (string)$c->id ? 'selected' : '' }}>{{ $c->name }}</option>
|
||||
@endforeach
|
||||
</x-searchable-select>
|
||||
</div>
|
||||
@ -1280,6 +1280,13 @@
|
||||
window.history.pushState({}, '', url);
|
||||
// 先讓 Preline (HSSelect 等) 初始化完成,再由 Alpine 接管
|
||||
if (window.HSStaticMethods?.autoInit) window.HSStaticMethods.autoInit();
|
||||
// Re-sync company filter HSSelect display after AJAX DOM replacement.
|
||||
const filterSelect = container.querySelector('select[name="filter_company_id"]');
|
||||
if (filterSelect) {
|
||||
const selectedValue = (filterSelect.value ?? '').trim();
|
||||
const hsSelect = window.HSSelect?.getInstance(filterSelect);
|
||||
if (hsSelect) hsSelect.setValue(selectedValue || ' ');
|
||||
}
|
||||
requestAnimationFrame(() => {
|
||||
if (window.Alpine?.initTree) window.Alpine.initTree(container);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user