3

In Magento 2, the previous Account Setting edit form has a different layout, like for changing password user has to select the checkbox and then text boxes for password updates pop up,

I am changing that layout

So I removed all the checkboxes, and put change password in the different form. and also I included first name, last name, email address, gender, dob in password form and display it to none.

The issue is, password update doesn't work, On digging up I found the script code in edit form phtml

<script type="text/x-magento-init">
{
    "[data-role=change-email], [data-role=change-password]": {
        "changeEmailPassword": {
            "titleChangeEmail": "<?= $block->escapeJs($block->escapeHtml(__('Change Email'))) ?>",
            "titleChangePassword": "<?= $block->escapeJs($block->escapeHtml(__('Change Password'))) ?>",
            "titleChangeEmailAndPassword": "<?= $block->escapeJs($block->escapeHtml(__('Change Email and Password'))) ?>"
        }
    },
    "[data-container=new-password]": {
        "passwordStrengthIndicator": {
            "formSelector": "form.form-edit-account"
        }
    }
}

Code for checkboxes which I removed

 <div class="field choice">
        <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?= $block->escapeHtmlAttr(__('Change Email')) ?>" class="checkbox" />
        <label class="label" for="change-email"><span><?= $block->escapeHtml(__('Change Email')) ?></span></label>
    </div>
    <div class="field choice">
        <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?= $block->escapeHtmlAttr(__('Change Password')) ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
        <label class="label" for="change-password"><span><?= $block->escapeHtml(__('Change Password')) ?></span></label>
    </div>

So that's clear script is linked to those checkboxes, as it assigns some kind of listener to [data-role=change-email] and [data-role=change-password], How can I change it to so that my Update Password will work?

I even tried adding those checkboxes and displayed it none still it didn't work.

0

You may try this quick-fix type solution as provided below.

1) Instead removeing I made the two containers div hidden for Email and Password change check box.

<div class="field choice" style="display:none;">
        <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?= $block->escapeHtmlAttr(__('Change Email')) ?>" class="checkbox" />
        <label class="label" for="change-email"><span><?= $block->escapeHtml(__('Change Email')) ?></span></label>
    </div>
    <div class="field choice" style="display:none;">
        <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?= $block->escapeHtmlAttr(__('Change Password')) ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
        <label class="label" for="change-password"><span><?= $block->escapeHtml(__('Change Password')) ?></span></label>
    </div>

2) use a window load event to trigger click event for Email and Password change checkbox.

<script type="text/javascript">
        requirejs(['jquery'],function(jQuery){
            (function($) {
                $(window).load(function () {
                    $("#change-password").trigger('click');
                    $("#change-email").trigger('click');


                });                 

            })(jQuery);
        });
</script> 

3) Do not put change password in the different form.

enter image description here

  • this has a flaw, whenever you want to update name only then you have to update the password also, as its a required field – summu Feb 22 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.