mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 20:18:38 +02:00
refactored the js
This commit is contained in:
parent
a4e2292798
commit
d9cd4aeb4d
2 changed files with 4 additions and 15 deletions
|
@ -458,10 +458,12 @@ export class NameserverForm {
|
||||||
* This ensures that only the latest alert is displayed to the user.
|
* This ensures that only the latest alert is displayed to the user.
|
||||||
*/
|
*/
|
||||||
resetAlerts() {
|
resetAlerts() {
|
||||||
const mainContent = document.querySelector("main#main-content");
|
const mainContent = document.getElementById("main-content");
|
||||||
if (mainContent) {
|
if (mainContent) {
|
||||||
// Remove all alert elements within the main content area
|
// Remove all alert elements within the main content area
|
||||||
mainContent.querySelectorAll(".usa-alert").forEach(alert => alert.remove());
|
mainContent.querySelectorAll(".usa-alert").forEach(alert => alert.remove());
|
||||||
|
} else {
|
||||||
|
console.warn("Expecting main-content DOM element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +476,7 @@ export class NameserverForm {
|
||||||
addAlert(level, message) {
|
addAlert(level, message) {
|
||||||
this.resetAlerts(); // Remove any existing alerts before adding a new one
|
this.resetAlerts(); // Remove any existing alerts before adding a new one
|
||||||
|
|
||||||
const mainContent = document.querySelector("main#main-content");
|
const mainContent = document.getElementById("main-content");
|
||||||
if (!mainContent) return;
|
if (!mainContent) return;
|
||||||
|
|
||||||
// Create a new alert div with appropriate classes based on alert level
|
// Create a new alert div with appropriate classes based on alert level
|
||||||
|
|
|
@ -84,19 +84,6 @@ export function getCsrfToken() {
|
||||||
return document.querySelector('input[name="csrfmiddlewaretoken"]').value;
|
return document.querySelector('input[name="csrfmiddlewaretoken"]').value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to submit a form
|
|
||||||
* @param {} form_id - the id of the form to be submitted
|
|
||||||
*/
|
|
||||||
export function submitForm(form_id) {
|
|
||||||
let form = document.getElementById(form_id);
|
|
||||||
if (form) {
|
|
||||||
form.submit();
|
|
||||||
} else {
|
|
||||||
console.error("Form '" + form_id + "' not found.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to strip HTML tags
|
* Helper function to strip HTML tags
|
||||||
* THIS IS NOT SUITABLE FOR SANITIZING DANGEROUS STRINGS
|
* THIS IS NOT SUITABLE FOR SANITIZING DANGEROUS STRINGS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue