diff --git a/app/assets/javascripts/autofocus.js b/app/assets/javascripts/autofocus.js index 2d276953f..c280b7454 100644 --- a/app/assets/javascripts/autofocus.js +++ b/app/assets/javascripts/autofocus.js @@ -3,6 +3,11 @@ Modules.Autofocus = function() { this.start = function(component) { + var forceFocus = $(component).data('forceFocus'); + + // if the page loads with a scroll position, we can't assume the item to focus onload + // is still where users intend to start + if (($(window).scrollTop() > 0) && !forceFocus) { return; } $('input, textarea, select', component).eq(0).trigger('focus'); diff --git a/app/templates/views/send-test.html b/app/templates/views/send-test.html index c84c5fbce..8764b5479 100644 --- a/app/templates/views/send-test.html +++ b/app/templates/views/send-test.html @@ -16,7 +16,8 @@ {% call form_wrapper( class='js-stick-at-top-when-scrolling send-one-off-form' if template.template_type != 'sms' else 'send-one-off-form', - module="autofocus" + module="autofocus", + data_kwargs={'force-focus': True} ) %}