2013-12-03 51 views
0

我使用datePicker.js來顯示grails datePicker。我有開始和結束日期g:datePicker jQuery UI日期選取器

g:datePicker class='StartDatetime' precision='minute' 

現在我試圖設置datePicker的最小和最大日期。將此代碼置於準備就緒狀態不起作用。我需要對代碼中的其他地方進行更改以查看函數的工作方式嗎?

$("#StartDatetime").datepicker({ 
    onSelect: function (selected) { 
     $("#EndDatetime_input").datepicker("option", "minDate", selected) 
    } 
}); 

$("#EndDatetime_input").datepicker({ 
    onSelect: function (selected) { 
     $("#StartDatetime_input").datepicker("option", "maxDate", selected) 
    } 
}); 
+0

你是不是想用Grails的日期選擇器或datepicker.js? – Alidad

+0

我正在使用,但顯示datePicker我使用jquery-ui選取器。 – monal86

回答

0

替換的src /模板/支架/ renderEditor.template 'renderDateEditor' 用下面的代碼:

private renderDateEditor(domainClass, property) { 
    def precision = (property.type == Date || property.type == java.sql.Date || property.type == Calendar) ? "day" : "minute"; 
    if (!cp) { 
     return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" />" 
    } else { 
     if (!cp.editable) { 
      return "\${${domainInstance}?.${property.name}?.toString()}" 
     } else { 
      def out = new StringBuffer("") 

      out << "<input type=\"text\" name=\"${property.name}_datepicker\" id=\"${property.name}_datepicker\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" formatName=\"dateonly.date.format\" />\"/>" 
      out << "<input type=\"hidden\" name=\"${property.name}_day\" id=\"${property.name}_day\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"dd\" />\"/>" 
      out << "<input type=\"hidden\" name=\"${property.name}_month\" id=\"${property.name}_month\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"MM\" />\"/>" 
      out << "<input type=\"hidden\" name=\"${property.name}_year\" id=\"${property.name}_year\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"yyyy\" />\"/>" 
      out << """<g:javascript> 
         \$(document).ready(function() { 
          \$("#${property.name}_datepicker").datepicker({ 
           dateFormat:'dd/MM/yy', 
           onClose: function(dateText, inst) { 
             var date = new Date(dateText.replace(/(\\d+).(\\d+).(\\d+)/, '\$3/\$2/\$1')); 
             if (!isNaN(date)) { 
              \$("#${property.name}_month").val(date.getMonth()+1); 
              \$("#${property.name}_day").val(date.getDate()); 
              \$("#${property.name}_year").val(date.getFullYear()); 
             } 
             }, 
           showAnim: "slide", 
           showOptions: {direction: 'up'}, 
           showOn: "both", 
           autoSize: true, 
           constrainInput: true, 
           showButtonPanel: true 
          }); 
         }) 
        </g:javascript>""" 
      return out.toString() 
     } 
    }}