mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 00:42:16 +02:00
Merge pull request #3519 from cisagov/za/2822-focus-reset
#2822: Focus reset on 'Add another site' button for request form - [AG]
This commit is contained in:
commit
d7aed42b6a
2 changed files with 37 additions and 7 deletions
|
@ -2,11 +2,41 @@ import { submitForm } from './helpers.js';
|
|||
|
||||
export function initDomainRequestForm() {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const button = document.getElementById("domain-request-form-submit-button");
|
||||
if (button) {
|
||||
button.addEventListener("click", function () {
|
||||
submitForm("submit-domain-request-form");
|
||||
});
|
||||
}
|
||||
// These are the request steps in DomainRequestWizard, such as current_websites or review
|
||||
initRequestStepCurrentWebsitesListener();
|
||||
initRequestStepReviewListener();
|
||||
});
|
||||
}
|
||||
|
||||
function initRequestStepReviewListener() {
|
||||
const button = document.getElementById("domain-request-form-submit-button");
|
||||
if (button) {
|
||||
button.addEventListener("click", function () {
|
||||
submitForm("submit-domain-request-form");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initRequestStepCurrentWebsitesListener() {
|
||||
//register-form-step
|
||||
const addAnotherSiteButton = document.getElementById("submit-domain-request--site-button");
|
||||
if (addAnotherSiteButton) {
|
||||
// Check for focus state in sessionStorage
|
||||
const focusTarget = sessionStorage.getItem("lastFocusedElement");
|
||||
if (focusTarget) {
|
||||
document.querySelector(focusTarget)?.focus();
|
||||
}
|
||||
// Add form submit handler to store focus state
|
||||
const form = document.querySelector("form");
|
||||
if (form) {
|
||||
form.addEventListener("submit", () => {
|
||||
const activeElement = document.activeElement;
|
||||
if (activeElement) {
|
||||
sessionStorage.setItem("lastFocusedElement", "#" + activeElement.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
// We only want to do this action once, so we clear out the session
|
||||
sessionStorage.removeItem("lastFocusedElement");
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
||||
<button type="submit" name="submit_button" value="save" class="usa-button usa-button--with-icon usa-button--unstyled">
|
||||
<button id="submit-domain-request--site-button" type="submit" name="submit_button" value="save" class="usa-button usa-button--with-icon usa-button--unstyled">
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="{%static 'img/sprite.svg'%}#add_circle"></use>
|
||||
</svg><span class="margin-left-05">Add another site</span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue