From 4d26f29fceab4583fd84eee53356c071dbf2baa6 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 17 Mar 2015 09:55:08 -0500
Subject: [PATCH] search: Fix search on create date

This addresses the issue where the advanced search dialog was submitted
before the date picker inputs were fixed up. This problem arises out of a
difference between the agent's date formatting preference and the server
being able to process that date format. The date pickers are reformated to
yyyy-mm-dd before submission; however, for advanced search, the submission
happened before the inputs were fixed up.

This patch addresses the issue by manually fixing up the date in the
submission routine for the advanced search dialog.
---
 scp/js/scp.js | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/scp/js/scp.js b/scp/js/scp.js
index d1493f590..f3d9ab3e1 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -391,6 +391,7 @@ var scp_prep = function() {
         var fObj = $(this);
         var elem = $('#advanced-search');
         $('#result-count').html('');
+        fixupDatePickers.call(this);
         $.ajax({
                 url: "ajax.php/tickets/search",
                 data: fObj.serialize(),
@@ -447,18 +448,21 @@ var scp_prep = function() {
 
 $(document).ready(scp_prep);
 $(document).on('pjax:end', scp_prep);
-$(document).on('submit', 'form', function() {
+var fixupDatePickers = function() {
     // Reformat dates
     $('.dp', $(this)).each(function(i, e) {
         var $e = $(e),
             d = $e.datepicker('getDate');
-        if (!d) return;
+        if (!d || $e.data('fixed')) return;
         var day = ('0'+d.getDate()).substr(-2),
             month = ('0'+(d.getMonth()+1)).substr(-2),
             year = d.getFullYear();
         $e.val(year+'-'+month+'-'+day);
+        $e.data('fixed', true);
+        $e.on('change', function() { $(this).data('fixed', false); });
     });
-});
+};
+$(document).on('submit', 'form', fixupDatePickers);
 
     /************ global inits *****************/
 
-- 
GitLab