From f982f9f2d8ad6066f393093677dfb7f7bb10d6b1 Mon Sep 17 00:00:00 2001 From: Michael Olund Date: Thu, 7 Feb 2019 15:47:14 -0800 Subject: [PATCH] REP-934 - Date formats --- edivorce/apps/core/static/js/ajax.js | 21 ++++++++++----------- edivorce/apps/core/static/js/main.js | 11 +++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/edivorce/apps/core/static/js/ajax.js b/edivorce/apps/core/static/js/ajax.js index e545e000..d8bb9a24 100644 --- a/edivorce/apps/core/static/js/ajax.js +++ b/edivorce/apps/core/static/js/ajax.js @@ -5,17 +5,6 @@ var ajaxOnChange = function () { // show/hide additional information if needed reveal(el); - 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); - } - var skipAjax = el.attr('data-skip_ajax'); if (skipAjax !== undefined && skipAjax === "true") { return; @@ -33,6 +22,16 @@ 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/main.js b/edivorce/apps/core/static/js/main.js index 118aca5f..7aae6709 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -836,6 +836,17 @@ var mirrorOnChange = function(e) { if (e.which === 9) { return; } + + // fix incorrect date formats / don't mirror invalid dates + if ($(this).is('.date-picker')) { + var isFuture = $(this).is('.date-picker-future'); + if (isValidDate($(this).val(), isFuture) && $(this).val().trim().length) { + $(this).val(moment(stringToDate($(this).val())).format('MMM D, YYYY')); + } else { + return; + } + } + var target_select = $(this).attr("data-mirror_target"); var scale_factor_identifier = $(this).attr("data-mirror_scale"); var broadcast_change = $(this).attr("data-mirror_broadcast_change");