Skip to content

Commit

Permalink
Added fix to email input focus behaviour when there is an error
Browse files Browse the repository at this point in the history
Currently when users makes mistake or leaves the email input empty the focus returns to the begining of the page causing the user to have to travel across multiple elements to be able to re-enter their email. With this fix the focus goes back to the email input element.
  • Loading branch information
lucascumsille committed May 7, 2024
1 parent c34f2ee commit 23a43e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions web/cobrands/fixmystreet/fixmystreet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,12 +1512,23 @@ $.extend(fixmystreet.set_up, {
});
$('body').on('click', '#alert_email_button', function(e) {
e.preventDefault();

var emailInput = $(this).closest('.js-alert-list').find('input[type=email]');
var emailValue = emailInput.val();

if (jQuery.validator.methods.notEmail.call({ optional: function() { return false; } }, emailValue)) {
emailInput.focus();
return;
}

var form = $('<form/>').attr({ method:'post', action:"/alert/subscribe" });
form.append($('<input name="alert" value="Subscribe me to an email alert" type="hidden" />'));

$(this).closest('.js-alert-list').find('textarea, input[type=email], input[type=text], input[type=hidden], input[type=radio]:checked').each(function() {
var $v = $(this);
$('<input/>').attr({ name:$v.attr('name'), value:$v.val(), type:'hidden' }).appendTo(form);
});

$('body').append(form);
form.trigger('submit');
});
Expand Down

0 comments on commit 23a43e2

Please sign in to comment.