سامانه صدور فاکتور و حسابداری
fix: preserve live combobox queries across invoice rows
Davood Mehraban committed
Oct 10, 2026 at 21:22 UTC
c4868c1f09ea871fe7a3ba335eab75e5de522dd2
1 file changed
+5
-5
js/ux-hardening-r2.js
+5
-5
@@ -26,11 +26,11 @@
26
const input=document.createElement('input');input.type='text';input.className='form-control finora-combobox-input';input.autocomplete='off';input.placeholder=select.classList.contains('row-product-select')||select.classList.contains('pur-prod')?'انتخاب یا جستجوی کالا (نام، کد، مشخصه...)':'انتخاب یا جستجو...';wrap.insertBefore(input,select);
27
const list=document.createElement('div');list.className='finora-combobox-list';list.setAttribute('role','listbox');list.style.cssText='display:none;position:absolute;z-index:1200;top:calc(100% + 3px);right:0;left:0;max-height:240px;overflow:auto;background:var(--card,#fff);border:1px solid var(--border,#cbd5e1);border-radius:8px;box-shadow:0 8px 24px rgba(15,23,42,.14)';wrap.appendChild(list);
28
const close=()=>{list.style.display='none'};
29
- const render=()=>{const rows=comboOptions(select,input.value);list.innerHTML=rows.length?rows.map(o=>'<button type="button" class="finora-combobox-option" data-value="'+String(o.value).replace(/&/g,'&').replace(/"/g,'"')+'" style="display:block;width:100%;text-align:right;border:0;border-bottom:1px solid var(--border,#e2e8f0);background:transparent;padding:9px 10px;cursor:pointer;color:inherit">'+comboLabel(o)+'</button>').join(''):'<div class="finora-combobox-empty" style="padding:10px;color:var(--text-muted)">موردی پیدا نشد</div>';list.style.display='block'};
30
- const sync=()=>{const o=select.options[select.selectedIndex];input.value=o&&o.value?comboLabel(o):''};
31
- input.addEventListener('focus',render);input.addEventListener('input',render);input.addEventListener('keydown',e=>{if(e.key==='Escape'){close();input.blur();return}if(e.key==='Enter'){const b=list.querySelector('.finora-combobox-option');if(b){e.preventDefault();b.click()}}});
32
- list.addEventListener('mousedown',e=>{const b=e.target.closest('.finora-combobox-option');if(!b)return;e.preventDefault();select.value=b.dataset.value;select.dispatchEvent(new Event('change',{bubbles:true}));sync();close()});
33
- select.addEventListener('change',sync);document.addEventListener('mousedown',e=>{if(!wrap.contains(e.target))close()});new MutationObserver(sync).observe(select,{childList:true,subtree:true});sync();
29
+ const render=()=>{const rows=comboOptions(select,input.value);list.replaceChildren();if(!rows.length){const empty=document.createElement('div');empty.className='finora-combobox-empty';empty.textContent='موردی پیدا نشد';empty.style.cssText='padding:10px;color:var(--text-muted)';list.appendChild(empty)}else for(const o of rows){const b=document.createElement('button');b.type='button';b.className='finora-combobox-option';b.dataset.value=o.value;b.textContent=comboLabel(o);b.style.cssText='display:block;width:100%;text-align:right;border:0;border-bottom:1px solid var(--border,#e2e8f0);background:transparent;padding:9px 10px;cursor:pointer;color:inherit';list.appendChild(b)}list.style.display='block'};
30
+ const sync=()=>{const o=select.options[select.selectedIndex];if(document.activeElement===input&&input.dataset.searchDirty==='1')return;input.value=o&&o.value?comboLabel(o):''};
31
+ input.addEventListener('focus',()=>{input.dataset.searchDirty='1';render()});input.addEventListener('input',()=>{input.dataset.searchDirty='1';render()});input.addEventListener('keydown',e=>{if(e.key==='Escape'){close();input.dataset.searchDirty='0';sync();input.blur();return}if(e.key==='Enter'){const b=list.querySelector('.finora-combobox-option');if(b){e.preventDefault();b.click()}}});
32
+ list.addEventListener('mousedown',e=>{const b=e.target.closest('.finora-combobox-option');if(!b)return;e.preventDefault();select.value=b.dataset.value;input.dataset.searchDirty='0';select.dispatchEvent(new Event('change',{bubbles:true}));sync();close()});
33
+ select.addEventListener('change',()=>{input.dataset.searchDirty='0';sync()});document.addEventListener('mousedown',e=>{if(!wrap.contains(e.target)){close();input.dataset.searchDirty='0';sync()}});new MutationObserver(()=>{if(input.dataset.searchDirty!=='1')sync()}).observe(select,{childList:true,subtree:true});sync();
34
}
35
function refreshProductOptionMetadata(){document.querySelectorAll('.row-product-select,.pur-prod').forEach(sel=>[...sel.options].forEach(o=>{if(!o.value)return;const p=typeof getMyProducts==='function'?getMyProducts().find(x=>x.id===o.value):null;if(!p)return;o.dataset.price=String(sel.classList.contains('pur-prod')?(p.buy_price||0):(p.sale_price||0));o.dataset.unit=p.unit||'عدد';o.dataset.search=[p.code,p.name,p.spec,p.barcode,p.internal_id,p.official_id,p.category,p.subcategory].filter(Boolean).join(' ').toLowerCase()}))}
36
function enhanceAll(){refreshProductOptionMetadata();document.querySelectorAll('select').forEach(finoraRefreshSearchableSelect)}