From aebbbcd03d0eac15fd5c9138d42e5bc783175c42 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 26 Nov 2021 00:03:58 +0530 Subject: [PATCH] settings: Show error in change password modal if input is empty. We show "Please enter your password" error inside the modal if the "Old password" input is empty and "Please choose a new password" error if the "New password" input is empty and do not send a request to server. Fixes #19901. --- static/js/settings_account.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/static/js/settings_account.js b/static/js/settings_account.js index a5fa3a17a8..6de16bb7a2 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -459,12 +459,29 @@ export function set_up() { e.preventDefault(); e.stopPropagation(); const change_password_error = $("#change_password_modal").find("#dialog_error"); + change_password_error.hide(); const data = { old_password: $("#old_password").val(), new_password: $("#new_password").val(), }; + function show_error_message(rendered_error_msg) { + change_password_error.html(rendered_error_msg); + change_password_error.addClass("alert-error").show(); + dialog_widget.hide_dialog_spinner(); + } + + if (data.old_password === "") { + show_error_message($t_html({defaultMessage: "Please enter your password"})); + return; + } + + if (data.new_password === "") { + show_error_message($t_html({defaultMessage: "Please choose a new password"})); + return; + } + const new_pw_field = $("#new_password"); const new_pw = data.new_password; if (new_pw !== "") {