Skip to content

Commit

Permalink
account-settings: Pass delivery email to change email modal.
Browse files Browse the repository at this point in the history
When we converted the change email form to a dialog widget modal,
in commit f43d3b9, the page_params value for delivery email
that was being referenced in the handlebars template
`change_email_modal.hbs` was not set, so instead an empty string
was the initial input value. Because the email change dialog
widget post_render callback sets the input value to the same
delivery email, the fact that the email was not being set when
the template was initially rendered was not noticable.

Passes the page_params.delivery_email to the html parameter in
dialog_widget.launch so that the template has the initial value
set when the form is initially rendered. Removes the now redundant
post_render callback, which resets the initial input value to the
same delivery email.
  • Loading branch information
laurynmm authored and timabbott committed Mar 22, 2023
1 parent 25fb810 commit 90205a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 1 addition & 8 deletions web/src/settings_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,25 +718,18 @@ export function set_up() {
);
}

function change_email_post_render() {
const $input_elem = $("#change_email_form").find("input[name='email']");
const email = $("#change_email_button").text().trim();
$input_elem.val(email);
}

$("#change_email_button").on("click", (e) => {
e.preventDefault();
e.stopPropagation();
if (settings_data.user_can_change_email()) {
dialog_widget.launch({
html_heading: $t_html({defaultMessage: "Change email"}),
html_body: render_change_email_modal(),
html_body: render_change_email_modal({delivery_email: page_params.delivery_email}),
html_submit_button: $t_html({defaultMessage: "Change"}),
loading_spinner: true,
id: "change_email_modal",
form_id: "change_email_form",
on_click: do_change_email,
post_render: change_email_post_render,
on_shown() {
$("#change_email_form input").trigger("focus");
},
Expand Down
2 changes: 1 addition & 1 deletion web/templates/change_email_modal.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form id="change_email_form" class="new-style">
<label for="email">{{t "New email" }}</label>
<input type="text" name="email" value="{{ page_params.delivery_email }}" autocomplete="off" spellcheck="false" autofocus="autofocus"/>
<input type="text" name="email" value="{{delivery_email}}" autocomplete="off" spellcheck="false" autofocus="autofocus"/>
</form>

0 comments on commit 90205a4

Please sign in to comment.