Skip to content
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

Settings Save button disable/enable #47444

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from

Conversation

psealock
Copy link
Contributor

@psealock psealock commented May 14, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes Partial fix for #47393

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Go to the all Settings screens and see the Save button is disabled. Make any change to the form and see that the Save button becomes enabled.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Update Settings to disable Save button unless modifications are made.

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 14, 2024
Copy link
Contributor

github-actions bot commented May 14, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@psealock psealock closed this May 15, 2024
@psealock psealock reopened this May 15, 2024
@psealock psealock marked this pull request as ready for review May 15, 2024 01:29
@psealock psealock changed the title Settings Save button disable/enable on dirty form Settings Save button disable/enable May 15, 2024
@psealock psealock requested review from a team, moon0326 and rjchow May 15, 2024 01:54
Copy link
Contributor

Hi @moon0326, @rjchow, @woocommerce/ghidorah

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

@moon0326 moon0326 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach! LGTM and tested well 👍 🚀

@github-actions github-actions bot added focus: e2e tests Issues related to e2e tests and removed focus: e2e tests Issues related to e2e tests labels May 15, 2024
@github-actions github-actions bot added the focus: e2e tests Issues related to e2e tests label May 21, 2024
@github-actions github-actions bot added focus: monorepo infrastructure Issues and PRs related to monorepo tooling. package: @woocommerce/components issues related to @woocommerce/components package: @woocommerce/data issues related to @woocommerce/data package: @woocommerce/experimental issues related to @woocommerce/experimental plugin: woocommerce beta tester Issues related to the WooCommerce Beta Tester plugin. labels May 21, 2024
@psealock psealock force-pushed the add/disabled-save-settings-pages branch from a84bf4b to ba78b2d Compare May 21, 2024 00:10
@github-actions github-actions bot removed package: @woocommerce/components issues related to @woocommerce/components plugin: woocommerce beta tester Issues related to the WooCommerce Beta Tester plugin. package: @woocommerce/data issues related to @woocommerce/data focus: monorepo infrastructure Issues and PRs related to monorepo tooling. package: @woocommerce/experimental issues related to @woocommerce/experimental labels May 21, 2024
Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this and adding the tests! 👍

I confirmed that the Save button is disabled when no modifications are made and enabled when modifications are made.

However, if we reset the form after making modifications, the Save button is still enabled. What do you think disabling the Save button again when the form is reset?

It seems that we can achieve this by storing the initial values of the form fields and comparing them with the current values whenever an input event occurs.

$(document).ready(function() {
    // Store the initial values of the form fields
    var initialFormState = $('#exampleForm').serialize();

    // Function to check if the form values have changed
    function checkFormChanges() {
        var currentFormState = $('#exampleForm').serialize();
        if (currentFormState === initialFormState) {
            $('#saveButton').prop('disabled', true);
        } else {
            $('#saveButton').prop('disabled', false);
        }
    }

    // Listen for changes in any of the form fields
    $('#exampleForm input').on('input', checkFormChanges);
});

@adrianduffell
Copy link
Contributor

What do you think disabling the Save button again when the form is reset?

That's a super idea @chihsuan! However I suggest we hold on it until we get feedback about the PR from developers (there will be communications about the change to mitigate risks to 3PD customization). I like that we're using an existing implementation to detect changes so I'd lean towards keeping our surface area small at first 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants