Datepicker display error

Datepicker display error

Hi, everyone!

I have two fields with datepicker inside a dialog. When I use them inside this dialog, everything works fine. The problem is when I close my dialog and re-open it to do other requests. My datepicker re-initialize whitout selecting any fields and do not close again.

I've tried to close it manually with the dialog's close property but when I re-open it, my datepicker does'nt open again.
Any idea?

  1. My form

  2. <div>
  3.     <form onsubmit="return false;" id="formDialog">
  4.       <input type="hidden" name="id" value="${id}"/>
  5.       <input type="hidden" name="domain" value="${domain}"/>
  6.       <label for="all">Period</label> <br>
  7.       <input type="text" class="datePicker" name="startDate"/>&nbsp;to&nbsp;
  8.       <input type="text" class="datePicker" name="endDate"/>
  9.       <input type="submit" value="Search" class="btn"/>
  10.     </form>
  11.     <div id="formDataPanel">

  12.     </div>

  13. </div>
  14. <asset:javascript src="jqueryui/jquery-ui.js"/>
  15. <script type="text/javascript">

  16.   $(".datePicker").datepicker({
  17.     dateFormat:"dd/mm/yy",
  18.     onClose: function () {
  19.       $(this).datepicker('refresh');
  20.     }
  21.   });

  22.   $("#formDialog").submit(function() {
  23.       // $(".datePicker").datepicker("destroy")
  24.       $.ajax(
  25.         $("#appContext").val() + "myEndpoint",
  26.         {
  27.           data:$("#formDialog").serialize(),
  28.           success: function(data, textStatus, jqXHR) {
  29.             $("#formDataPanel").html(data)
  30.           }
  31.         }
  32.       )
  33.       return false;
  34.   })
  35. </script>


  1. My other js file
  2. //= require jqueryui/jquery-ui.js
  3. //= require_self

  4. function functionToRequest(domain, id) {

  5.     $("#selector")
  6.         .load($("#appContext").val() + "auditoria/domain?id=" + id + "&domain=" + domain)
  7.         .dialog({
  8.             modal:true,
  9.             closeOnEscape:true,
  10.             title:'MyTitle',
  11.             width:'70vw',
  12.             height:300
  13.         });
  14. }

  15. jQuery(document).ready(function() {
  16.     $("body").append("<div id=\"selector\"></div>")
  17. })