-
Notifications
You must be signed in to change notification settings - Fork 41
Update gateway setting toggle logic #3095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,31 +8,77 @@ | |
|
|
||
| const { __ } = wp.i18n; | ||
|
|
||
| function onGatewayToggle( { gateway, settings, checked } ) { | ||
| if ( 'square' === gateway && checked ) { | ||
| syncRepeat( settings.get( 0 ) ); | ||
| function updateGatewaySettingsVisibility( settings ) { | ||
| const typeDropdown = settings.querySelector( 'select.frm_trans_type' ); | ||
| if ( ! typeDropdown ) { | ||
| return; | ||
| } | ||
|
|
||
| syncCurrency( gateway, settings.get( 0 ) ); | ||
| if ( 'recurring' === typeDropdown.value ) { | ||
| const activeGateways = Array.from( settings.querySelectorAll( '[name*="[post_content][gateway]"]:checked' ) ).map( function( el ) { | ||
| return el.value; | ||
| } ); | ||
|
|
||
| const typeDropdown = settings.get( 0 ).querySelector( 'select.frm_trans_type' ); | ||
| if ( typeDropdown && 'recurring' !== typeDropdown.value ) { | ||
| settings.get( 0 ).querySelectorAll( '.frm_trans_sub_opts' ).forEach( | ||
| settings.querySelectorAll( '.frm_trans_sub_opts' ).forEach( | ||
| function( subOpts ) { | ||
| subOpts.style.display = 'none'; | ||
| // Check if this setting has a show_* class for any active gateway | ||
| const hasActiveGatewayClass = Array.from( subOpts.classList ).some( function( className ) { | ||
| return activeGateways.some( function( gateway ) { | ||
| return className === 'show_' + gateway; | ||
| } ); | ||
| } ); | ||
|
|
||
| if ( hasActiveGatewayClass ) { | ||
| subOpts.classList.remove( 'frm_hidden' ); | ||
| if ( subOpts.classList.contains( 'frm_grid_container' ) ) { | ||
| subOpts.style.display = 'grid'; | ||
| } | ||
|
Comment on lines
+31
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visible sub-options can stay hidden after mode/gateway switches
💡 Suggested fix- if ( hasActiveGatewayClass ) {
- subOpts.classList.remove( 'frm_hidden' );
- if ( subOpts.classList.contains( 'frm_grid_container' ) ) {
- subOpts.style.display = 'grid';
- }
+ if ( hasActiveGatewayClass ) {
+ subOpts.classList.remove( 'frm_hidden' );
+ subOpts.style.display = subOpts.classList.contains( 'frm_grid_container' ) ? 'grid' : '';
} else {
@@
- } else {
- // Show if it has no show_* class (shared setting)
- subOpts.classList.remove( 'frm_hidden' );
- if ( subOpts.classList.contains( 'frm_grid_container' ) ) {
- subOpts.style.display = 'grid';
- }
+ } else {
+ // Show if it has no show_* class (shared setting)
+ subOpts.classList.remove( 'frm_hidden' );
+ subOpts.style.display = subOpts.classList.contains( 'frm_grid_container' ) ? 'grid' : '';
}
}Also applies to: 42-45, 55-56 🤖 Prompt for AI Agents |
||
| } else { | ||
| // Check if it has any show_* class for a different gateway | ||
| const hasAnyGatewayClass = Array.from( subOpts.classList ).some( function( className ) { | ||
| return className.startsWith( 'show_' ); | ||
| } ); | ||
|
|
||
| if ( hasAnyGatewayClass ) { | ||
| // Hide if it has a show_* class but not for any active gateway | ||
| subOpts.classList.add( 'frm_hidden' ); | ||
| subOpts.style.display = 'none'; | ||
| } else { | ||
| // Show if it has no show_* class (shared setting) | ||
| subOpts.classList.remove( 'frm_hidden' ); | ||
| if ( subOpts.classList.contains( 'frm_grid_container' ) ) { | ||
| subOpts.style.display = 'grid'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| settings.querySelectorAll( '.frm_trans_sub_opts' ).forEach( | ||
| function( subOpts ) { | ||
| subOpts.classList.add( 'frm_hidden' ); | ||
| subOpts.style.display = 'none'; | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| function onGatewayToggle( { gateway, settings, checked } ) { | ||
| if ( 'square' === gateway && checked ) { | ||
| syncRepeat( settings.get( 0 ) ); | ||
| } | ||
|
|
||
| syncCurrency( gateway, settings.get( 0 ) ); | ||
|
|
||
| updateGatewaySettingsVisibility( settings.get( 0 ) ); | ||
|
|
||
| const captureSetting = settings.get( 0 ).querySelector( '[name*="[post_content][capture]"]' ); | ||
| if ( captureSetting ) { | ||
| const wrapper = captureSetting.closest( '.frm_gateway_no_recur' ); | ||
| if ( wrapper ) { | ||
| if ( 'square' === gateway ) { | ||
| wrapper.style.display = 'none'; | ||
| } else if ( 'recurring' !== typeDropdown.value ) { | ||
| // Capture appearing with Stripe selected and recurring selected. | ||
| wrapper.style.removeProperty( 'display' ); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -48,21 +94,15 @@ | |
| if ( squareGatewayOption?.checked ) { | ||
| syncRepeat( settings ); | ||
| } | ||
|
|
||
| updateGatewaySettingsVisibility( settings ); | ||
| } | ||
|
|
||
| function onToggleSub() { | ||
| const target = this; | ||
| setTimeout( function() { | ||
| const settings = target.closest( '.frm_form_action_settings' ); | ||
| const squareIsActive = settings.querySelector( '[name*="[post_content][gateway]"][value="square"]' ).checked; | ||
|
|
||
| settings.querySelectorAll( '.frm_trans_sub_opts' ).forEach( | ||
| function( subOpts ) { | ||
| if ( subOpts.classList.contains( 'show_stripe' ) && ! subOpts.classList.contains( 'show_square' ) && squareIsActive ) { | ||
| subOpts.style.display = 'none'; | ||
| } | ||
| } | ||
| ); | ||
| updateGatewaySettingsVisibility( settings ); | ||
| }, 0 ); | ||
| } | ||
|
|
||
|
|
@@ -132,6 +172,7 @@ | |
| } | ||
|
|
||
| newDropdown.closest( '.frm_trans_sub_opts' )?.classList.add( 'show_square' ); | ||
| newDropdown.closest( '.frm_trans_sub_opts' )?.classList.remove( 'frm_hidden' ); | ||
|
|
||
| const stripeLabel = intervalCount.closest( '.frm_trans_sub_opts' )?.querySelector( 'label' ); | ||
| if ( stripeLabel?.textContent.includes( 'Repeat Every' ) ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ES2015 (ES6), we can use template literals instead of string concatenation.