Skip to content

Commit

Permalink
lint touchpoints form too
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 committed May 7, 2024
1 parent 8d83589 commit 7be8557
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
42 changes: 13 additions & 29 deletions assets/js/touchpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Form components are namespaced under 'fba' = 'Feedback Analytics'
"use strict";

function FBAform(d, N) {
function FBAform(d) {
return {
formId: "2a6e9509",
formComponent: function () {
Expand Down Expand Up @@ -81,8 +81,8 @@ function FBAform(d, N) {
);
}
var phoneElements = d.querySelectorAll("input[type='tel']");
for (var i = 0; i < phoneElements.length; i++) {
phoneElements[i].addEventListener(
for (var j = 0; j < phoneElements.length; j++) {
phoneElements[j].addEventListener(
"keyup",
this.handlePhoneInput.bind(this),
false,
Expand Down Expand Up @@ -169,21 +169,6 @@ function FBAform(d, N) {
}
e.srcElement.value = number;
},
handleEmailInput: function (e) {
var EmailRegex =
/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email = e.srcElement.value.trim();
if (email.length == 0) {
return;
}
result = EmailRegex.test(email);
if (!result) {
showWarning($(this), "Please enter a valid email address");
} else {
showValid($(this));
}
e.srcElement.value = number;
},
handleSubmitClick: function (e) {
e.preventDefault();
this.resetErrors();
Expand Down Expand Up @@ -292,7 +277,7 @@ function FBAform(d, N) {
delete questions[item.name];
} else {
var EmailRegex =
/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
/^([a-zA-Z0-9_.+-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (EmailRegex.test(item.value)) delete questions[item.name];
}
});
Expand Down Expand Up @@ -368,10 +353,10 @@ function FBAform(d, N) {
var elem = form.querySelector(".usa-form-group--error");
if (elem == null) return;
elem.setAttribute("class", "question");
var elem = form.querySelector("#input-error-message");
if (elem != null) elem.parentNode.removeChild(elem);
elem = form.querySelector("#input-error");
if (elem != null) elem.parentNode.removeChild(elem);
var newElem = form.querySelector("#input-error-message");
if (newElem != null) newElem.parentNode.removeChild(newElem);
newElem = form.querySelector("#input-error");
if (newElem != null) newElem.parentNode.removeChild(newElem);
},
textCounter: function (field, maxlimit) {
var countfield = field.parentNode.querySelector(".counter-msg");
Expand Down Expand Up @@ -440,7 +425,7 @@ function FBAform(d, N) {
successText: function () {
return "Thanks for your feedback!";
},
showFormSuccess: function (e) {
showFormSuccess: function () {
var formComponent = this.formComponent();
var formElement = this.formElement();
var alertElement = formComponent.querySelector(".fba-alert");
Expand Down Expand Up @@ -500,7 +485,6 @@ function FBAform(d, N) {
formSuccess: function (e) {
// Clear the alert box
var formComponent = this.formComponent();
var alertElement = formComponent.querySelector(".fba-alert");
var alertElementBody =
formComponent.getElementsByClassName("usa-alert__text")[0];
var alertErrorElement = formComponent.querySelector(".fba-alert-error");
Expand Down Expand Up @@ -530,7 +514,7 @@ function FBAform(d, N) {
var errors = jsonResponse.messages;

for (var err in errors) {
if (errors.hasOwnProperty(err)) {
if (Object.prototype.hasOwnProperty.call(errors, err)) {
alertErrorElementBody.innerHTML += err;
alertErrorElementBody.innerHTML += " ";
alertErrorElementBody.innerHTML += errors[err];
Expand Down Expand Up @@ -622,8 +606,8 @@ function FBAform(d, N) {
);
}

for (var i = 0; i < nextButtons.length; i++) {
nextButtons[i].addEventListener(
for (var k = 0; k < nextButtons.length; k++) {
nextButtons[k].addEventListener(
"click",
function (e) {
e.preventDefault();
Expand All @@ -645,4 +629,4 @@ var formOptions = {
};

// Create unique Touchpoints form object
const touchpointForm2a6e9509 = new FBAform(document, window).init(formOptions);
export const touchpointForm2a6e9509 = new FBAform(document, window).init(formOptions);
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default [
"**/uswds*.js",
"**/main.js",
"**/anchor*.js",
"**/touchpoints.js",
],
}
];

0 comments on commit 7be8557

Please sign in to comment.