[FIX] 修正機台設定公司篩選下拉選單兩項問題
1. 選取公司後自動觸發 AJAX 篩選,無需手動按搜尋按鈕 2. 修正重設按鈕邏輯,透過 HSSelect.setValue() 正確清除 Preline 下拉選單 UI 顯示 3. 調整 fetchTabContent 的 Preline autoInit 與 Alpine initTree 初始化順序,以 requestAnimationFrame 確保 DOM 更新完畢後才執行 Alpine,解決 AJAX 後下拉選單選中狀態遺失的問題
This commit is contained in:
parent
ac48546c76
commit
90192dbed9
@ -230,7 +230,8 @@
|
||||
|
||||
<!-- 公司篩選下拉選單 (僅 System Admin 可見) -->
|
||||
@if(auth()->user()->isSystemAdmin())
|
||||
<div class="w-full md:w-64 relative focus-within:z-[20]">
|
||||
<div class="w-full md:w-64 relative focus-within:z-[20]"
|
||||
@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>
|
||||
@ -244,7 +245,19 @@
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>
|
||||
</button>
|
||||
<button type="button"
|
||||
@click="$el.closest('form').querySelector('input[name=search_machine]').value=''; @if(auth()->user()->isSystemAdmin()) $el.closest('form').querySelector('select[name=filter_company_id]').value=''; @endif $el.closest('form').dispatchEvent(new Event('submit'));"
|
||||
@click="
|
||||
const form = $el.closest('form');
|
||||
form.querySelector('input[name=search_machine]').value = '';
|
||||
@if(auth()->user()->isSystemAdmin())
|
||||
const nativeSel = form.querySelector('select[name=filter_company_id]');
|
||||
if (nativeSel) {
|
||||
nativeSel.value = ' ';
|
||||
const inst = window.HSSelect?.getInstance(nativeSel);
|
||||
if (inst) inst.setValue(' ');
|
||||
}
|
||||
@endif
|
||||
form.dispatchEvent(new Event('submit'));
|
||||
"
|
||||
class="p-2.5 rounded-xl bg-slate-100 dark:bg-slate-800 text-slate-500 hover:bg-slate-200 dark:hover:bg-slate-700 transition-all" title="{{ __('Reset') }}">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
|
||||
</button>
|
||||
@ -1265,8 +1278,11 @@
|
||||
if (newContent && container) {
|
||||
container.innerHTML = newContent.innerHTML;
|
||||
window.history.pushState({}, '', url);
|
||||
// 先讓 Preline (HSSelect 等) 初始化完成,再由 Alpine 接管
|
||||
if (window.HSStaticMethods?.autoInit) window.HSStaticMethods.autoInit();
|
||||
if (window.Alpine?.initTree) window.Alpine.initTree(container);
|
||||
requestAnimationFrame(() => {
|
||||
if (window.Alpine?.initTree) window.Alpine.initTree(container);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('AJAX Load Failed:', e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user