Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to focus order #4952

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion web/cobrands/fixmystreet/fixmystreet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,15 @@

var focusFirstVisibleInput = function() {
// Ignore logged-in form here, because it should all be pre-filled already!
$('#form_sign_in_yes input, #form_sign_in_no input').filter(':visible').eq(0).trigger('focus');
var $inputs = $('#form_sign_in_yes input, #form_sign_in_no input').filter(':visible');

// Check if there is an element with class .form-section-preview. This will allow users to rectify any previews answers without having to circle around the whole page.
var $formSectionPreview = $('.form-section-preview').first();
if ($formSectionPreview.length) {
$formSectionPreview.children().first().trigger('focus');
} else {
$inputs.eq(0).trigger('focus');

Check warning on line 1340 in web/cobrands/fixmystreet/fixmystreet.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet/fixmystreet.js#L1340

Added line #L1340 was not covered by tests
}
};

// Display tweak
Expand Down Expand Up @@ -1512,12 +1520,23 @@
});
$('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();

Check warning on line 1525 in web/cobrands/fixmystreet/fixmystreet.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet/fixmystreet.js#L1524-L1525

Added lines #L1524 - L1525 were not covered by tests

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

Check warning on line 1529 in web/cobrands/fixmystreet/fixmystreet.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet/fixmystreet.js#L1527-L1529

Added lines #L1527 - L1529 were not covered by tests
}

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