Make WordPress Core

Changeset 58137


Ignore:
Timestamp:
05/12/2024 06:43:19 PM (5 months ago)
Author:
joedolson
Message:

Users: Add JS confirmation if user profile has unsaved changes.

Add a confirmation dialog when users navigate away from the user profile screen if they have unsaved changes to prevent data loss.

Props ashokrane, karlijnbk, diedeexterkate, jwgoedert, joedolson, swissspidy, afercia.
Fixes #40493.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/user-profile.js

    r57702 r58137  
    66(function($) {
    77    var updateLock = false,
     8        isSubmitting = false,
    89        __ = wp.i18n.__,
    910        $pass1Row,
     
    1617        $submitButton,
    1718        currentPass,
     19        $form,
     20        originalFormContent,
    1821        $passwordWrapper;
    1922
     
    455458        bindPasswordForm();
    456459        bindPasswordResetLink();
     460        $submitButtons.on( 'click', function() {
     461            isSubmitting = true;
     462        });
     463
     464        $form = $( '#your-profile, #createuser' );
     465        originalFormContent = $form.serialize();
    457466    });
    458467
     
    482491            return __( 'Your new password has not been saved.' );
    483492        }
    484     } );
     493        if ( originalFormContent !== $form.serialize() && ! isSubmitting ) {
     494            return __( 'Changes that you made may not be saved.' );
     495        }
     496    });
    485497
    486498    /*
Note: See TracChangeset for help on using the changeset viewer.