frontend.js
1 lines
| 1 | (()=>{const{InputData:t}=JetFormBuilderAbstract,{ListingAddTemplateWatcher:e,ListingTemplateClick:i}=JetFormBuilderFunctions,{addAction:n,addFilter:r}=JetPlugins.hooks;function s(){t.call(this),this.isSupported=function(t){return"appointment"===t.dataset.field},this.addListeners=function(){const[t]=this.nodes;jQuery(t).on("change",()=>{this.value.current=t.value}),this.reporting.makeInvalid=()=>{},this.reporting.makeValid=()=>{}},this.onObserve=function(){t.prototype.onObserve.call(this),this.callable=null,this.value.sanitize(t=>["{}","[]"].includes(t)?"":t)}}function o(){t.call(this),this.providerArgs={},this.isSupported=function(t){return t.classList.contains("appointment-provider")},this.setNode=function(e){t.prototype.setNode.call(this,e),this.name=e.dataset?.field||e.name,this.providerArgs=JSON.parse(e.dataset.args)},this.checkIsRequired=function(){if(this.providerArgs?.args_str)return this.providerArgs?.args_str?.includes("required");{const[t]=this.nodes;return t.hasAttribute("required")}},this.addListeners=function(){const[t]=this.nodes;t.addEventListener("change",({target:t})=>{this.value.current=t.value}),"SELECT"===t.nodeName&&t.addEventListener("blur",()=>this.reportOnBlur()),this.addListingTemplateListener(),this.addServiceListener()},this.addServiceListener=function(){if(!this.providerArgs?.service?.field)return;const t=this.root.getInput(this.providerArgs.service.field);t&&t.watch(()=>{this.silenceSet(null)})},this.addListingTemplateListener=function(){const[t]=this.nodes;"DIV"===t.nodeName&&(t.addEventListener("click",i),e(this))},this.onObserve=function(){t.prototype.onObserve.call(this),this.callable=null},this.reQueryValue=function(){}}s.prototype=Object.create(t.prototype),o.prototype=Object.create(t.prototype),n("jet.fb.observe.before","jet-form-builder/appointment-compatibility",function(t){const{rootNode:e}=t;for(const t of e.querySelectorAll(".jet-apb-calendar-wrapper")){const e=t.querySelector("input[data-field]");"appointment"===e.dataset.field&&(e.dataset.jfbSync=1)}for(const t of e.querySelectorAll(".field-type-appointment-provider .appointment-provider"))t.dataset.jfbSync=1}),r("jet.fb.inputs","jet-form-builder/appointment-field",function(t){return[s,o,...t]}),n("jet.fb.input.makeReactive","jet-form-builder/appointment-compatibility",function(t){for(const e of t.root.getInputs()){if(e instanceof s){const[i]=e.nodes,n=i.closest(".appointment-calendar"),r=JSON.parse(n.dataset.args);r?.service?.field===t.name&&(t.callable.triggerJQuery=()=>{})}if(e instanceof o){const[i]=e.nodes,n=JSON.parse(i.dataset.args);n?.service?.field===t.name&&(t.callable.triggerJQuery=()=>{})}}}),n("jet.fb.multistep.page.init","jet-form-builder/appointment-compatibility/switch-page-on-change",function(t){const e=t.node.querySelectorAll('.appointment-provider[data-args*="data-switch"], .appointment-provider[data-switch="1"]');if(e?.length)for(const i of e)i.jfbSync.watch(()=>{i.jfbSync.value.current&&t.changePage(!1).then(()=>{}).catch(()=>{})})})})(); |