diff --git a/assets/build/frontend/multi.step.asset.php b/assets/build/frontend/multi.step.asset.php index e126843fc..3e3d1cf27 100644 --- a/assets/build/frontend/multi.step.asset.php +++ b/assets/build/frontend/multi.step.asset.php @@ -1 +1 @@ - array(), 'version' => '9457afa85f7e33a36e73'); + array(), 'version' => '45709365defdf608dab0'); diff --git a/assets/build/frontend/multi.step.js b/assets/build/frontend/multi.step.js index 9a112d0ee..62d934bfd 100644 --- a/assets/build/frontend/multi.step.js +++ b/assets/build/frontend/multi.step.js @@ -1 +1 @@ -(()=>{"use strict";const{ConditionItem:t}=JetFormBuilderAbstract;function e(){t.call(this),this.isSupported=function(t){return!!t?.page_state?.length},this.setOptions=function({page_state:t}){this.pageState=t},this.isPassed=function(){const t=this.list?.block?.page?.canSwitch?.current;return"active"===this.pageState&&!t}}e.prototype=Object.create(t.prototype);const i=e,{ReactiveVar:s,createConditionalBlock:n}=JetFormBuilderAbstract,{validateInputs:o,getOffsetTop:r,focusOnInvalidInput:a,populateInputs:c}=JetFormBuilderFunctions,{addAction:h,doAction:u}=JetPlugins.hooks;function d(t,e){this.node=t,this.index=+t.dataset.page,this.offset=+t.dataset.pageOffset,this.state=e,this.inputs=[],this.inputBindings=new Map,this.canSwitch=new s(null),this.isShow=new s(1===this.index),this.autoFocus=window.JetFormBuilderSettings?.auto_focus,this.initialObserveState=!1}d.prototype.observe=function(){this.isLast()||this.observeInputs(),this.canSwitch.make(),this.isShow.make(),this.isShow.watch(()=>{this.isShow.current?this.onShow():this.onHide()}),this.addButtonsListeners(),this.isFirst()&&(this.initialObserveState=!0,this.updateStateAsync().then(()=>{}).catch(()=>{})),this.updateOffsetByProgress(),h("jet.fb.observe.input.manual","jet-form-builder/page-state",t=>this.observeInput(t.nodes[0])),u("jet.fb.multistep.page.init",this)},d.prototype.observeInputs=function(){for(const t of this.node.querySelectorAll("[data-jfb-sync]")){const e=this.observeInput(t);e&&u("jet.fb.multistep.page.observed.input",e,this)}},d.prototype.observeInput=function(t){if(!this.isNodeBelongThis(t)||!t.hasOwnProperty("jfbSync")||t.jfbSync.hasParent())return!1;const e=t.jfbSync;return this.registerInput(e)},d.prototype.observeConditionalBlocks=function(){if(!this.isLast())for(const t of this.node.querySelectorAll("[data-jfb-conditional]")){if(!this.isNodeBelongThis(t))continue;const e=n(t,this.state.getRoot());for(const t of e.list.getConditions())if(t instanceof i){e.page=this,this.canSwitch.watch(()=>e.list.onChangeRelated());break}}},d.prototype.onShow=function(){this.node.classList.remove("jet-form-builder-page--hidden"),this.initialObserveState||(this.initialObserveState=!0,this.updateStateAsync().then(()=>{}).catch(()=>{}))},d.prototype.onHide=function(){this.node.classList.add("jet-form-builder-page--hidden")},d.prototype.updateState=function(){for(const t of this.getInputs())if(!t.reporting.validityState.current&&null!==t.reporting.validityState.current)return void(this.canSwitch.current=!1);this.canSwitch.current=!0},d.prototype.updateStateAsync=async function(t=!0){try{await o(this.getInputs(),t),this.canSwitch.current=!0}catch(t){this.canSwitch.current=!1}},d.prototype.addButtonsListeners=function(){const t=this.node.querySelectorAll(".jet-form-builder__next-page, .jet-form-builder__prev-page");for(const e of t){if(!this.isNodeBelongThis(e))continue;const t=e.classList.contains("jet-form-builder__prev-page");e.addEventListener("click",()=>this.changePage(t))}},d.prototype.changePage=async function(t){t?this.state.index.current=this.index-1:this.getLockState().current||(await this.updateStateAsync(!1),this.canSwitch.current?this.state.index.current=this.index+1:this.autoFocus&&a(this.getInputs()))},d.prototype.isNodeBelongThis=function(t){const e=t.closest(".jet-form-builder-page");return!!e&&e.isEqualNode(this.node)},d.prototype.getInputs=function(){return c(this.inputs)},d.prototype.getLockState=function(){var t;const e=this.state.getRoot();return(null!==(t=e?.parent?.root?.form)&&void 0!==t?t:e.form).lockState},d.prototype.isLast=function(){return this.state.isLastPage(this)},d.prototype.isFirst=function(){return this.state.isFirstPage(this)},d.prototype.handleInputEnter=function(t){t?.enterKey?.addFilter(()=>{const e=t.root.form;return e?!0===e.canTriggerEnterSubmit&&this.changePage().then(()=>{}).catch(()=>{}):this.changePage().then(()=>{}).catch(()=>{}),!1})},d.prototype.registerInput=function(t,{includeInValidation:e=!0}={}){if(!t||this.inputBindings.has(t))return t;this.handleInputEnter(t);const i={clearLoadingWatch:t.loading.watch(()=>{t.loading.current?this.canSwitch.current=!1:this.updateState()}),clearValidityWatch:null};return t.reporting.restrictions.length&&(this.inputs.push(t),i.clearValidityWatch=t.watchValidity(()=>this.updateState()),e||(this.inputs=this.inputs.filter(e=>e!==t))),this.inputBindings.set(t,i),t},d.prototype.unregisterInput=function(t){if(!this.inputBindings.has(t))return;const e=this.inputBindings.get(t);e?.clearLoadingWatch?.(),e?.clearValidityWatch?.(),this.inputBindings.delete(t),this.inputs=this.inputs.filter(e=>e!==t)},d.prototype.getTrackedInputs=function(){return Array.from(this.inputBindings.keys())},d.prototype.getOffsetTop=function(){return r(this.node)-this.offset},d.prototype.updateOffsetByProgress=function(){this.state?.progress?.node&&(this.offset+=+this.state.progress.node.clientHeight)};const p=d,l=function(t,e){this.node=t,this.state=e,this.state.index.watch(()=>this.updateItems()),this.updateItems=function(){const{current:t}=this.state.index;for(const e of this.node.children){const i=+e.dataset.page;inew p(t,this)),this.elements.forEach(t=>t.observe()),this.elements.forEach(t=>t.observeConditionalBlocks());const{submitter:e}=this.getRoot().getSubmit();e.hasOwnProperty("status")&&e.watchReset(()=>{this.index.current=1})},this.onChangeIndex=function(){for(const t of this.getPages())t.isShow.current=t.index===this.index.current;window?.jQuery(document)?.trigger("jet-form-builder/switch-page")},this.getCurrentPage=function(){for(const t of this.getPages())if(t.isShow.current)return t;return!1},this.getPages=function(){return this.elements},this.getScopeNode=function(){var t;return null!==(t=this.block?.node)&&void 0!==t?t:this.root.rootNode},this.getRoot=function(){var t;return null!==(t=this.block?.root)&&void 0!==t?t:this.root},this.isLastPage=function(t){return this.elements.at(-1)===t},this.isFirstPage=function(t){return this.elements[0]===t},this.onReady=function(){m("jet.fb.multistep.init",this)}};function y(t){const e=new b;e.setScope(t);const i=[];for(const t of e.getScopeNode().childNodes)t?.classList?.contains("jet-form-builder-page")&&i.push(t);return i.length?(e.setProgress(),e.setPages(i),e):e}const{addAction:S,addFilter:w}=JetPlugins.hooks,{getScrollParent:v}=JetFormBuilderFunctions;S("jet.fb.observe.after","jet-form-builder/multi-step",function(t){const e=y(t);e.getPages()?.length&&(t.multistep=e,e.onReady())},15),S("jet.fb.conditional.init","jet-form-builder/multi-step",function(t){const e=y(t);e.getPages()?.length&&(t.multistep=e,e.onReady())}),w("jet.fb.conditional.types","jet-form-builder/multi-step",function(t){return[i,...t]}),S("jet.fb.multistep.init","jet-form-builder/multi-step/autoscroll",function(t){window?.JetFormBuilderSettings?.scroll_on_next&&t.index.watch(()=>{const e=t.getCurrentPage(),i=v(e.node),s=e.getOffsetTop();i?.scrollTo?.({top:s,behavior:"smooth"})})})})(); \ No newline at end of file +(()=>{"use strict";const{ConditionItem:t}=JetFormBuilderAbstract;function e(){t.call(this),this.isSupported=function(t){return!!t?.page_state?.length},this.setOptions=function({page_state:t}){this.pageState=t},this.isPassed=function(){const t=this.list?.block?.page?.canSwitch?.current;return"active"===this.pageState&&!t}}e.prototype=Object.create(t.prototype);const i=e,{ReactiveVar:s,createConditionalBlock:n}=JetFormBuilderAbstract,{validateInputs:o,getOffsetTop:r,focusOnInvalidInput:a,populateInputs:c}=JetFormBuilderFunctions,{addAction:h,doAction:u}=JetPlugins.hooks;function d(t,e){this.node=t,this.index=+t.dataset.page,this.offset=+t.dataset.pageOffset,this.state=e,this.inputs=[],this.inputBindings=new Map,this.canSwitch=new s(null),this.isShow=new s(1===this.index),this.autoFocus=window.JetFormBuilderSettings?.auto_focus,this.initialObserveState=!1}d.prototype.observe=function(){this.isLast()||this.observeInputs(),this.canSwitch.make(),this.isShow.make(),this.isShow.watch(()=>{this.isShow.current?this.onShow():this.onHide()}),this.addButtonsListeners(),this.isFirst()&&(this.initialObserveState=!0,this.updateStateAsync().then(()=>{}).catch(()=>{})),this.updateOffsetByProgress(),h("jet.fb.observe.input.manual","jet-form-builder/page-state",t=>this.observeInput(t.nodes[0])),u("jet.fb.multistep.page.init",this)},d.prototype.observeInputs=function(){for(const t of this.node.querySelectorAll("[data-jfb-sync]")){const e=this.observeInput(t);e&&u("jet.fb.multistep.page.observed.input",e,this)}},d.prototype.observeInput=function(t){if(!this.isNodeBelongThis(t)||!t.hasOwnProperty("jfbSync")||t.jfbSync.hasParent())return!1;const e=t.jfbSync;return this.registerInput(e)},d.prototype.observeConditionalBlocks=function(){if(!this.isLast())for(const t of this.node.querySelectorAll("[data-jfb-conditional]")){if(!this.isNodeBelongThis(t))continue;const e=n(t,this.state.getRoot());for(const t of e.list.getConditions())if(t instanceof i){e.page=this,this.canSwitch.watch(()=>e.list.onChangeRelated());break}}},d.prototype.onShow=function(){this.node.classList.remove("jet-form-builder-page--hidden"),this.initialObserveState||(this.initialObserveState=!0,this.updateStateAsync().then(()=>{}).catch(()=>{}))},d.prototype.onHide=function(){this.node.classList.add("jet-form-builder-page--hidden")},d.prototype.updateState=function(){for(const t of this.getInputs())if(!t.reporting.validityState.current&&null!==t.reporting.validityState.current)return void(this.canSwitch.current=!1);this.canSwitch.current=!0},d.prototype.updateStateAsync=async function(t=!0){try{await o(this.getInputs(),t),this.canSwitch.current=!0}catch(t){this.canSwitch.current=!1}},d.prototype.addButtonsListeners=function(){const t=this.node.querySelectorAll(".jet-form-builder__next-page, .jet-form-builder__prev-page");for(const e of t){if(!this.isNodeBelongThis(e))continue;const t=e.classList.contains("jet-form-builder__prev-page");e.addEventListener("click",()=>this.changePage(t))}},d.prototype.changePage=async function(t){t?this.state.index.current=this.index-1:this.isLast()||this.getLockState().current||(await this.updateStateAsync(!1),this.canSwitch.current?this.state.index.current=this.index+1:this.autoFocus&&a(this.getInputs()))},d.prototype.isNodeBelongThis=function(t){const e=t.closest(".jet-form-builder-page");return!!e&&e.isEqualNode(this.node)},d.prototype.getInputs=function(){return c(this.inputs)},d.prototype.getLockState=function(){var t;const e=this.state.getRoot();return(null!==(t=e?.parent?.root?.form)&&void 0!==t?t:e.form).lockState},d.prototype.isLast=function(){return this.state.isLastPage(this)},d.prototype.isFirst=function(){return this.state.isFirstPage(this)},d.prototype.handleInputEnter=function(t){t?.enterKey?.addFilter(()=>{const e=t.root.form;return e?!0===e.canTriggerEnterSubmit&&this.changePage().then(()=>{}).catch(()=>{}):this.changePage().then(()=>{}).catch(()=>{}),!1})},d.prototype.registerInput=function(t,{includeInValidation:e=!0}={}){if(!t||this.inputBindings.has(t))return t;this.handleInputEnter(t);const i={clearLoadingWatch:t.loading.watch(()=>{t.loading.current?this.canSwitch.current=!1:this.updateState()}),clearValidityWatch:null};return t.reporting.restrictions.length&&(this.inputs.push(t),i.clearValidityWatch=t.watchValidity(()=>this.updateState()),e||(this.inputs=this.inputs.filter(e=>e!==t))),this.inputBindings.set(t,i),t},d.prototype.unregisterInput=function(t){if(!this.inputBindings.has(t))return;const e=this.inputBindings.get(t);e?.clearLoadingWatch?.(),e?.clearValidityWatch?.(),this.inputBindings.delete(t),this.inputs=this.inputs.filter(e=>e!==t)},d.prototype.getTrackedInputs=function(){return Array.from(this.inputBindings.keys())},d.prototype.getOffsetTop=function(){return r(this.node)-this.offset},d.prototype.updateOffsetByProgress=function(){this.state?.progress?.node&&(this.offset+=+this.state.progress.node.clientHeight)};const p=d,l=function(t,e){this.node=t,this.state=e,this.state.index.watch(()=>this.updateItems()),this.updateItems=function(){const{current:t}=this.state.index;for(const e of this.node.children){const i=+e.dataset.page;inew p(t,this)),this.elements.forEach(t=>t.observe()),this.elements.forEach(t=>t.observeConditionalBlocks());const{submitter:e}=this.getRoot().getSubmit();e.hasOwnProperty("status")&&e.watchReset(()=>{this.index.current=1})},this.onChangeIndex=function(){for(const t of this.getPages())t.isShow.current=t.index===this.index.current;window?.jQuery(document)?.trigger("jet-form-builder/switch-page")},this.getCurrentPage=function(){for(const t of this.getPages())if(t.isShow.current)return t;return!1},this.getPages=function(){return this.elements},this.getScopeNode=function(){var t;return null!==(t=this.block?.node)&&void 0!==t?t:this.root.rootNode},this.getRoot=function(){var t;return null!==(t=this.block?.root)&&void 0!==t?t:this.root},this.isLastPage=function(t){return this.elements.at(-1)===t},this.isFirstPage=function(t){return this.elements[0]===t},this.onReady=function(){m("jet.fb.multistep.init",this)}};function y(t){const e=new b;e.setScope(t);const i=[];for(const t of e.getScopeNode().childNodes)t?.classList?.contains("jet-form-builder-page")&&i.push(t);return i.length?(e.setProgress(),e.setPages(i),e):e}const{addAction:S,addFilter:w}=JetPlugins.hooks,{getScrollParent:v}=JetFormBuilderFunctions;S("jet.fb.observe.after","jet-form-builder/multi-step",function(t){const e=y(t);e.getPages()?.length&&(t.multistep=e,e.onReady())},15),S("jet.fb.conditional.init","jet-form-builder/multi-step",function(t){const e=y(t);e.getPages()?.length&&(t.multistep=e,e.onReady())}),w("jet.fb.conditional.types","jet-form-builder/multi-step",function(t){return[i,...t]}),S("jet.fb.multistep.init","jet-form-builder/multi-step/autoscroll",function(t){window?.JetFormBuilderSettings?.scroll_on_next&&t.index.watch(()=>{const e=t.getCurrentPage(),i=v(e.node),s=e.getOffsetTop();i?.scrollTo?.({top:s,behavior:"smooth"})})})})(); \ No newline at end of file diff --git a/assets/src/frontend/multi.step/PageState.js b/assets/src/frontend/multi.step/PageState.js index a30d38c8d..c92f9cf89 100644 --- a/assets/src/frontend/multi.step/PageState.js +++ b/assets/src/frontend/multi.step/PageState.js @@ -219,6 +219,10 @@ PageState.prototype.changePage = async function ( isBack ) { return; } + if ( this.isLast() ) { + return; + } + if ( this.getLockState().current ) { return; } diff --git a/modules/switch-page-on-change/assets/build/frontend.asset.php b/modules/switch-page-on-change/assets/build/frontend.asset.php index c1a96c632..3d5d555df 100644 --- a/modules/switch-page-on-change/assets/build/frontend.asset.php +++ b/modules/switch-page-on-change/assets/build/frontend.asset.php @@ -1 +1 @@ - array(), 'version' => '37cff6ecfd5e3812f98c'); + array(), 'version' => '3d37e5f797b261c2ae1f'); diff --git a/modules/switch-page-on-change/assets/build/frontend.js b/modules/switch-page-on-change/assets/build/frontend.js index c7f8d9b1a..c7b051144 100644 --- a/modules/switch-page-on-change/assets/build/frontend.js +++ b/modules/switch-page-on-change/assets/build/frontend.js @@ -1 +1 @@ -(()=>{const{addAction:e}=JetPlugins.hooks,{isEmpty:t}=JetFormBuilderFunctions;e("jet.fb.multistep.page.init","jet-form-builder/switch-page-on-change",(function(e){e.node.addEventListener("click",(t=>{if("radio"===t.target.type){const c=t.target.closest(".jet-form-builder__field-wrap");c&&c.querySelector(".check-mark-control")?t.target.checked&&e.changePage(!1).then((()=>{})).catch((()=>{})):setTimeout((()=>{t.target.checked&&e.changePage(!1).then((()=>{})).catch((()=>{}))}),10)}}));const c=e.node.querySelectorAll(".jet-fb-switch-page-on-change");if(c)for(const n of c){let c=n;n.hasOwnProperty("jfbSync")||(c=n.querySelector("input, select")),c?.jfbSync&&e.isNodeBelongThis(c)&&c.jfbSync.watch((()=>{t(c.jfbSync.getValue())||e.changePage(!1).then((()=>{})).catch((()=>{}))}))}}))})(); \ No newline at end of file +(()=>{const{addAction:e}=JetPlugins.hooks,{isEmpty:t}=JetFormBuilderFunctions;e("jet.fb.multistep.page.init","jet-form-builder/switch-page-on-change",function(e){const c=()=>e.changePage(!1).then(()=>{}).catch(()=>{});e.node.addEventListener("click",t=>{if("radio"!==t.target.type)return;const n=(o=t.target,o?.closest(".jet-fb-switch-page-on-change"));var o;if(!n||!e.isNodeBelongThis(n))return;const r=t.target.closest(".jet-form-builder__field-wrap");r?.querySelector(".check-mark-control")?t.target.checked&&c():setTimeout(()=>{t.target.checked&&c()},10)});const n=e.node.querySelectorAll(".jet-fb-switch-page-on-change");if(n)for(const o of n){let n=o;o.hasOwnProperty("jfbSync")||(n=o.querySelector("input, select")),n?.jfbSync&&e.isNodeBelongThis(n)&&n.jfbSync.watch(()=>{t(n.jfbSync.getValue())||c()})}})})(); \ No newline at end of file diff --git a/modules/switch-page-on-change/assets/src/frontend/main.js b/modules/switch-page-on-change/assets/src/frontend/main.js index 11818d695..837bf66e3 100644 --- a/modules/switch-page-on-change/assets/src/frontend/main.js +++ b/modules/switch-page-on-change/assets/src/frontend/main.js @@ -11,26 +11,42 @@ addAction( * @param page {PageState} */ function ( page ) { - // Handle click events for radio inputs to allow re-selection + const getSwitchWrapper = ( node ) => node?.closest( + '.jet-fb-switch-page-on-change', + ); + + const changePage = () => page.changePage( false ) + .then( () => {} ) + .catch( () => {} ); + + // Handle click events for enabled radio inputs to allow re-selection. page.node.addEventListener( 'click', ( event ) => { - // Check if this is a radio input - if ( event.target.type === 'radio' ) { - // Check if there's a check-mark-control in the same wrapper - const wrapper = event.target.closest( '.jet-form-builder__field-wrap' ); - if ( wrapper && wrapper.querySelector( '.check-mark-control' ) ) { - if ( event.target.checked ) { - page.changePage( false ).then( () => {} ).catch( () => {} ); - } - } else { - // For regular radio inputs without check-mark, also handle clicks - // Small delay to ensure the value is updated - setTimeout( () => { - if ( event.target.checked ) { - page.changePage( false ).then( () => {} ).catch( () => {} ); - } - }, 10 ); + if ( event.target.type !== 'radio' ) { + return; + } + + const switchWrapper = getSwitchWrapper( event.target ); + + if ( !switchWrapper || !page.isNodeBelongThis( switchWrapper ) ) { + return; + } + + const wrapper = event.target.closest( '.jet-form-builder__field-wrap' ); + if ( wrapper?.querySelector( '.check-mark-control' ) ) { + if ( event.target.checked ) { + changePage(); } + + return; } + + // For regular radio inputs without check-mark, allow click-driven + // transitions after the checked state has updated. + setTimeout( () => { + if ( event.target.checked ) { + changePage(); + } + }, 10 ); } ); const wrappers = page.node.querySelectorAll( @@ -53,8 +69,8 @@ addAction( if ( isEmpty( node.jfbSync.getValue() ) ) { return; } - page.changePage( false ).then( () => {} ).catch( () => {} ); + changePage(); } ); } }, -); \ No newline at end of file +);