
new-request-agency.js
About this file
Restrictions are made to prevent the user from typing non-numeric values into the phone and fax fields.
Upon selecting title and description of the request, the user is able to see an example of the title and description in a tooltip popover.
The user can create a new request but needs to classify the type of the request. When the user changes the type, a warning is displayed. User can then choose to go through with the change or cancel the change.
Required fields are given the data-parsley-required attribute and error messages are displayed if requirements are not met. Upon validating the form, if validation fails, the window is then scrolled to the invalid input location.
Upon clicking submit, the processing bar is displayed and the submit button is hidden to prevent the user from submitting/clicking multiple times.
Character counts are displayed for the fields of the new request form.
Code Issues
- The span code for displaying error message is repeated several times for lines 142-168. Recommend putting the span string into a variable.
-
The
if
statement below uses a mix of&&
and||
. Recommend creating a function to check for address validation.if ($("#email").parsley().isValid() || $("#phone").parsley().isValid() || $("#fax").parsley().isValid() || ($("#address-line-1").parsley().isValid() && $("#state").parsley().isValid() && $("#zipcode").parsley().isValid() && $("#city").parsley().isValid()) ) {
- The function for validating the request form runs from line 230 to line 290. Recommend refactoring the function code by creating functions for separate parts of the function, such as scrolling to input when validation fails.
Code Check Report
221:54 warning Function has a complexity of 18 complexity ✖ 1 problem (0 errors, 1 warning)
Documentation drawn from source code
/**
* Created by atan on 9/14/16.
*/
/* globals characterCounter: true */
/* globals getRequestAgencyInstructions: true */
/* globals getCustomRequestForms: true */
/* globals renderCustomRequestForm: true */
/* globals processCustomRequestForms: true */
/* globals requiredFields: true */
$(document).ready(function () {
$(window).load(function () {
$("#phone").keypress(function (key) {
$("#fax").keypress(function (key) {
$("#request-agency").change(function () {
$(document).on("focus", ".request-type", function () {
$(targetId).off().change(function () {
$("#change-category-button").off().click(function () {
$("#cancel-change-category-button").off().click(function () {
$(document).on("click", ".panel-dismiss", function () {
$("#custom-request-form-additional-content").click(function () {
}).keydown(function (e) {
$("#request-file").change(function () {
$("#clear-file").click(function () {
$("#choose-file span[role=button]").bind("keypress keyup", function (e) {
$("#request-form").parsley().on("form:validate", function () {
$("#request-form").parsley().on("form:error", function () {
$(".parsley-required").each(function () {
$(".parsley-length").each(function () {
$("#submit").click(function () {
$("#request-file").change(function () {
$("#request-form").submit(function (e) {
$(this).submit(function () {
$("#request-title").keyup(function () {
$("#request-description").keyup(function () {
$("#first-name").keyup(function () {
$("#last-name").keyup(function () {
$("#user-title").keyup(function () {
$("#user-organization").keyup(function () {