From ac1727c5639a0f845cdf580d7e337467015e5d76 Mon Sep 17 00:00:00 2001 From: Charles Shin Date: Tue, 4 Jul 2017 14:44:23 -0700 Subject: [PATCH] DIV-490: Updated add_other_name field to allow maximum of 2 --- edivorce/apps/core/static/js/main.js | 24 ++++++++++++++++++- .../core/templates/question/02_claimant.html | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index f9ed0cc7..81b2c9b1 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -61,10 +61,26 @@ $(function () { } // Add name button adds new input field for adding other name + // Maximum of two other name fields allowed $("#btn_add_other_names").on('click', function () { - $('#other_names_fields').append($('#other_names_group').children().clone(true)); + if ($('#other_names_fields input[type=text]').length < 2) { + $('#other_names_fields').append($('#other_names_group').children().clone(true)); + } + + showWarningOtherName(); }); + // Show warning text when there are 2 other name fields + var showWarningOtherName = function() { + if ($('#other_names_fields input[type=text]').length >= 2) { + $('#btn_add_other_names').hide(); + $('#other_name_warning_message').html("

Max 2 other names, please enter only the name variations to be shown on the order from the court

"); + } + }; + + // show warning message if other name field is already at its maximum number when the page rendered + showWarningOtherName(); + $("#btn_add_reconciliation_periods").on('click', function () { $('#reconciliation_period_fields').append($('#reconciliation_period_group').children().clone()); // add event lister for newly added from_date field, to_date field, delete button, and date picker @@ -156,6 +172,12 @@ var deleteAddedField = function(e){ var button = $('#' + e.data.button_name); $(this).parent('div').remove(); + //enable btn_add_other_names button + if (button.prop('id') == "btn_add_other_names"){ + button.show(); + $('#other_name_warning_message').html(""); + } + // when there is only one field left, clear it instead of delete it if (field.find('input:text').length < 1){ button.triggerHandler('click'); diff --git a/edivorce/apps/core/templates/question/02_claimant.html b/edivorce/apps/core/templates/question/02_claimant.html index 9d151739..685ab487 100644 --- a/edivorce/apps/core/templates/question/02_claimant.html +++ b/edivorce/apps/core/templates/question/02_claimant.html @@ -85,6 +85,7 @@ {% endif %} +