mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 17:01:56 +02:00
Add focus on button
This commit is contained in:
parent
a2573b31be
commit
e5b0e357af
2 changed files with 36 additions and 7 deletions
|
@ -2,11 +2,40 @@ 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");
|
||||
});
|
||||
}
|
||||
initCurrentWebsites();
|
||||
initReview();
|
||||
});
|
||||
}
|
||||
|
||||
function initReview() {
|
||||
const button = document.getElementById("domain-request-form-submit-button");
|
||||
if (button) {
|
||||
button.addEventListener("click", function () {
|
||||
submitForm("submit-domain-request-form");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initCurrentWebsites() {
|
||||
//register-form-step
|
||||
const addAnotherSiteButton = document.getElementById("add-another-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="add-another-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