-
Notifications
You must be signed in to change notification settings - Fork 197
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
Fix settings form not redirecting to the correct tab when submitted #7424
Conversation
WordPress Dependencies ReportThe
This comment was automatically generated by the |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## trunk #7424 +/- ##
============================================
+ Coverage 51.04% 51.14% +0.10%
- Complexity 11167 11169 +2
============================================
Files 614 614
Lines 47148 47152 +4
Branches 405 405
============================================
+ Hits 24066 24117 +51
+ Misses 22755 22708 -47
Partials 327 327
Continue to review full report in Codecov by Sentry.
|
Thanks! I've updated the PR description. |
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.
Hi @m1r0 👋
This looks good to me overall and is working as expected. I just wanted to discuss another approach that won't involve session storage and can potentially help with testing.
What if we add a hidden input field here in this form
sensei/includes/class-sensei-settings-api.php
Line 540 in 51c2119
<form id="<?php echo esc_attr( $this->token ); ?>-form" action="options.php" method="post"> |
sensei/includes/class-sensei-settings-api.php
Line 306 in 51c2119
if ( 'default-settings' === $k ) { |
$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n";
$current_tab = isset( $_POST['tab'] ) ? sanitize_text_field( wp_unslash( $_POST['tab'] ) ) : 'default-settings';
$sections = array();
foreach ( $this->tabs as $k => $v ) {
$classes = 'tab';
if ( $current_tab === $k ) {
$classes .= ' current';
}
Also, currently, the Current tab highlight isn't working because of a bug here -
Lines 12 to 14 in 51c2119
$senseiSettings | |
.find( `[href="#${ sectionId }"]` ) | |
.addClass( 'current' ); |
We just need to replace
href=
with href$=
. And also should update the logic here a bit so that it doesn't remove the 'current' class in every case Line 7 in 51c2119
$senseiSettings.find( 'a.tab' ).removeClass( 'current' ); |
LMKWDYT!
Thanks for the nice suggestion, Imran. ❤️ I did try your idea but unfortunately, I've stumbled on the issue that the POST data is not accessible when the settings tabs are rendered. The form is submitting the data to Maybe it would be best to just not use JS to switch the tabs and move that responsibility to the backend. That will clean up all the messy tabs/hash logic but it will require some time to do. |
Absolutely agreed. That'd be best. But we'd still have to depend on JS a bit for the tabs. Otherwise we'd have to reload each time, which won't be a pleasant experience. But we should try to keep it at minimum.
Oh, in that case, we can just change the value of the input field |
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.
@Imran92, great input as always!
I've reworked the settings tabs to use &tab=default-settings
URL structure, taking your suggestions into account. It makes everything a lot simpler.
The navigation between the tabs is not refreshing the page, so it works as before. The old hash URL structure is also working so it's backwards compatible.
As a bonus, you can now navigate the tabs using the browser history, so navigating back/forward should work. 🙂
LMKWYT.
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.
Thanks for making the changes @m1r0 ! Looks good and works as expected <3
Resolves #7351
Related to #7415
Proposed Changes
This PR fixes the settings form always redirecting to the first (General) tab when the form is saved.
It also fixes the active tab highlight not working on the tabs menu.
It changes the URL structure to using params instead of hash (
#default-settings
->&tab=default-settings
) but the old structure is still supported.Testing Instructions
Emails
tab is working as before.Pre-Merge Checklist