let waitDatalistCounter=0;function getValueTypeParent(t){return t.is("select")?t.find("option:selected").val():"checkbox"===t.attr("type")&&t.prop("checked")?t.val():"radio"===t.attr("type")?t.find(":checked").val():t.is("input")||t.is("textarea")?t.val():""}function widgetSelectGetData(t,e){let a=$("#"+t.attr("list"));a.html("");let i={action:"datalist",activetab:t.closest("form").find('input[name="activetab"]').val(),field:t.attr("data-field"),fieldcode:t.attr("data-fieldcode"),fieldfilter:t.attr("data-fieldfilter"),fieldtitle:t.attr("data-fieldtitle"),required:"required"===t.attr("required")?1:0,source:t.attr("data-source"),term:getValueTypeParent(e)};$.ajax({method:"POST",url:window.location.href,data:i,dataType:"json",success:function(e){a.html(""),e.forEach((function(t){a.append('<option value="'+t.key+'">'+t.value+"</option>")})),t.change()},error:function(t){alert(t.status+" "+t.responseText)}})}$(document).ready((function(){$(".parentDatalist").each((function(){let t=$(this).attr("parent");if("undefined"===t||!1===t||""===t)return;let e=$(this),a=e.closest("form").find('[name="'+t+'"]');if(a.is("select")||["color","datetime-local","date","time"].includes(a.attr("type")))a.change((function(){widgetSelectGetData(e,a)}));else if("hidden"===a.attr("type")){var i=document.querySelector("[name='"+t+"']");i.addEventListener("change",(function(){widgetSelectGetData(e,a)}));let n=i.value;new MutationObserver((t=>{t.forEach((t=>{"attributes"===t.type&&"value"===t.attributeName&&i.value!==n&&(n=i.value,i.dispatchEvent(new Event("change")))}))})).observe(i,{attributes:!0})}else(a.is("input")||a.is("textarea"))&&a.keyup((async function(){waitDatalistCounter++;let t=waitDatalistCounter;if(await new Promise((t=>setTimeout(t,500))),t<waitDatalistCounter)return!1;widgetSelectGetData(e,a)}));a.length>0&&widgetSelectGetData(e,a)}))}));