From 15ca3699c4d9541cc214cda2547c437688641375 Mon Sep 17 00:00:00 2001 From: Gawuww Date: Mon, 11 May 2026 15:37:26 +0300 Subject: [PATCH] FIX: Radio field auto page switch stays scoped to enabled fields https://github.com/Crocoblock/issues-tracker/issues/18464 --- assets/build/frontend/multi.step.asset.php | 2 +- assets/build/frontend/multi.step.js | 2 +- assets/src/frontend/multi.step/PageState.js | 6 ++- .../assets/build/frontend.asset.php | 2 +- .../assets/build/frontend.js | 2 +- .../assets/src/frontend/main.js | 54 ++++++++++++------- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/assets/build/frontend/multi.step.asset.php b/assets/build/frontend/multi.step.asset.php index d7085aae5..679da67c6 100644 --- a/assets/build/frontend/multi.step.asset.php +++ b/assets/build/frontend/multi.step.asset.php @@ -1 +1 @@ - array(), 'version' => '36b86101cee675ffda25'); + array(), 'version' => '89fa3a12975cbac0b650'); diff --git a/assets/build/frontend/multi.step.js b/assets/build/frontend/multi.step.js index ad8d68bf1..6f55f9bc1 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 s=e,{ReactiveVar:i,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.canSwitch=new i(null),this.isShow=new i(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.handleInputEnter(e),e.loading.watch((()=>{e.loading.current?this.canSwitch.current=!1:this.updateState()})),e.reporting.restrictions.length?(this.inputs.push(e),e.watchValidity((()=>this.updateState())),e):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 s){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.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 s=+e.dataset.page;snew 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 S(t){const e=new b;e.setScope(t);const s=[];for(const t of e.getScopeNode().childNodes)t?.classList?.contains("jet-form-builder-page")&&s.push(t);return s.length?(e.setProgress(),e.setPages(s),e):e}const{addAction:y,addFilter:v}=JetPlugins.hooks,{getScrollParent:w}=JetFormBuilderFunctions;y("jet.fb.observe.after","jet-form-builder/multi-step",(function(t){const e=S(t);e.getPages()?.length&&(t.multistep=e,e.onReady())}),15),y("jet.fb.conditional.init","jet-form-builder/multi-step",(function(t){const e=S(t);e.getPages()?.length&&(t.multistep=e,e.onReady())})),v("jet.fb.conditional.types","jet-form-builder/multi-step",(function(t){return[s,...t]})),y("jet.fb.multistep.init","jet-form-builder/multi-step/autoscroll",(function(t){window?.JetFormBuilderSettings?.scroll_on_next&&t.index.watch((()=>{const e=t.getCurrentPage(),s=w(e.node),i=e.getOffsetTop();s?.scrollTo?.({top:i,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 s=e,{ReactiveVar:i,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.canSwitch=new i(null),this.isShow=new i(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.handleInputEnter(e),e.loading.watch(()=>{e.loading.current?this.canSwitch.current=!1:this.updateState()}),e.reporting.restrictions.length?(this.inputs.push(e),e.watchValidity(()=>this.updateState()),e):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 s){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.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 s=+e.dataset.page;snew 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 S(t){const e=new b;e.setScope(t);const s=[];for(const t of e.getScopeNode().childNodes)t?.classList?.contains("jet-form-builder-page")&&s.push(t);return s.length?(e.setProgress(),e.setPages(s),e):e}const{addAction:y,addFilter:v}=JetPlugins.hooks,{getScrollParent:w}=JetFormBuilderFunctions;y("jet.fb.observe.after","jet-form-builder/multi-step",function(t){const e=S(t);e.getPages()?.length&&(t.multistep=e,e.onReady())},15),y("jet.fb.conditional.init","jet-form-builder/multi-step",function(t){const e=S(t);e.getPages()?.length&&(t.multistep=e,e.onReady())}),v("jet.fb.conditional.types","jet-form-builder/multi-step",function(t){return[s,...t]}),y("jet.fb.multistep.init","jet-form-builder/multi-step/autoscroll",function(t){window?.JetFormBuilderSettings?.scroll_on_next&&t.index.watch(()=>{const e=t.getCurrentPage(),s=w(e.node),i=e.getOffsetTop();s?.scrollTo?.({top:i,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 ed7c42d3d..9ebb97e22 100644 --- a/assets/src/frontend/multi.step/PageState.js +++ b/assets/src/frontend/multi.step/PageState.js @@ -236,6 +236,10 @@ PageState.prototype.changePage = async function ( isBack ) { return; } + if ( this.isLast() ) { + return; + } + if ( this.getLockState().current ) { return; } @@ -323,4 +327,4 @@ PageState.prototype.updateOffsetByProgress = function () { this.offset += +this.state.progress.node.clientHeight; }; -export default PageState; \ No newline at end of file +export default PageState; 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 +);