From 875390876c65b96ce4ea334ac94586fab696116f Mon Sep 17 00:00:00 2001 From: Dominik Szopa Date: Tue, 12 Nov 2019 18:30:22 -0800 Subject: [PATCH 1/3] Add check for numbers in names except in AKA --- edivorce/apps/core/static/js/ajax.js | 29 +++++++++++-------- edivorce/apps/core/static/js/functions.js | 24 +++++++++++++++ edivorce/apps/core/static/js/main.js | 12 ++++++-- .../core/templates/partials/alias_field.html | 6 ++-- .../core/templates/question/02_claimant.html | 27 +++++++++++------ .../templates/question/03_respondent.html | 13 ++++++--- .../question/06_children_your_children.html | 4 ++- 7 files changed, 84 insertions(+), 31 deletions(-) diff --git a/edivorce/apps/core/static/js/ajax.js b/edivorce/apps/core/static/js/ajax.js index d8bb9a24..a6c9fe7e 100644 --- a/edivorce/apps/core/static/js/ajax.js +++ b/edivorce/apps/core/static/js/ajax.js @@ -5,6 +5,23 @@ var ajaxOnChange = function () { // show/hide additional information if needed reveal(el); + var question = el.prop('name'); + var value = getValue(el, question); + var isValid = true; + + // Check if date is in valid format DD/MM/YYYY + if (el.is(".date-picker") || el.is(".date-pickers") || el.is(".date-picker-future")){ + isValid = validateDate(el); + } + + if (el.is("#email_textbox")){ + isValid = validateEmail(el); + } + + if (el.is(".name")) { + isValid = validateName(el); + } + var skipAjax = el.attr('data-skip_ajax'); if (skipAjax !== undefined && skipAjax === "true") { return; @@ -20,18 +37,6 @@ var ajaxOnChange = function () { } } - var question = el.prop('name'); - var value = getValue(el, question); - var isValid = true; - - // Check if date is in valid format DD/MM/YYYY - if (el.is(".date-picker") || el.is(".date-pickers") || el.is(".date-picker-future")){ - isValid = validateDate(el); - } - - if (el.is("#email_textbox")){ - isValid = validateEmail(el); - } // special behaviour for radio button with textbox radioWithTextboxControl(el); diff --git a/edivorce/apps/core/static/js/functions.js b/edivorce/apps/core/static/js/functions.js index ff16042f..f334674d 100644 --- a/edivorce/apps/core/static/js/functions.js +++ b/edivorce/apps/core/static/js/functions.js @@ -355,6 +355,30 @@ var validateEmail = function(el){ } }; +var validateName = function(el){ + + console.log('validating name') + + el.closest('.form-group') + .removeClass('has-error') + .find('span.help-block') + .remove(); + + var value = el.val(); + var hasDigit = /\d/; + + // check to make sure there are no digits in the string, + // because CEIS won't accept it + if (hasDigit.test(value)){ + el.closest('.form-group') + .addClass('has-error') + .append('A name cannot have a number in it.'); + return false; + } + + return true; +} + var $DateFormat = 'M d, yyyy'; var MomentFormat = 'MMM D, YYYY'; diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index 86eda19d..fdef409a 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -22,7 +22,7 @@ $('input[type=number]').each(function() { $(window).load(function(){ $('#questions_modal, #terms_modal').modal('show'); - // Load child support act question text if child_suuport_in_order exist on the page and answered before. + // Load child support act question text if child_support_in_order exist on the page and answered before. var childSupport = $('input[name="child_support_in_order"]:checked'); if (childSupport !== undefined) { var wantChildSupport = childSupport.val() === 'NO' ? false : true; @@ -502,6 +502,8 @@ $(function () { var checkNoEmptyField = function() { var isNotEmpty = true; + var hasDigit = /\d/; + $('.children-questions .question-well').each(function () { var questionWell = $(this); questionWell.removeClass('hasError'); @@ -515,7 +517,13 @@ $(function () { isNotEmpty = false; questionWell.addClass('hasError'); } - } + } else if (inputField.id === 'childs_name') { + // check for digits in the name + if (hasDigit.test(inputField.value)) { + isNotEmpty = false; + questionWell.addClass('hasError'); + } + } } else if (inputField.type === 'radio') { if (questionWell.find('input:radio:checked').length === 0) { isNotEmpty = false; diff --git a/edivorce/apps/core/templates/partials/alias_field.html b/edivorce/apps/core/templates/partials/alias_field.html index 34333b58..a9a89b97 100644 --- a/edivorce/apps/core/templates/partials/alias_field.html +++ b/edivorce/apps/core/templates/partials/alias_field.html @@ -8,8 +8,8 @@ {% endcomment %} - + - {% input_field type="text" name=name value=value multiple="true" class="form-control response-textbox" %} - + {% input_field type="text" name=name value=value multiple="true" class="form-control response-textbox name" %} + \ No newline at end of file diff --git a/edivorce/apps/core/templates/question/02_claimant.html b/edivorce/apps/core/templates/question/02_claimant.html index 81f14c4c..e48d0be9 100644 --- a/edivorce/apps/core/templates/question/02_claimant.html +++ b/edivorce/apps/core/templates/question/02_claimant.html @@ -12,7 +12,9 @@

Please enter your name (as it appears on your marriage certificate or registration of marriage)

- {% input_field type="text" name="name_you" class="form-block input-wide response-textbox" %} + + {% input_field type="text" name="name_you" class="form-block input-wide response-textbox name" %} +