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