2012-08-07 79 views
0
$(".datepicker_1").datepicker({ 
      numberOfMonths: 2, 
      showButtonPanel: false, 
      minDate: new Date('<?php echo $st_date_sh.' '.$st_month_sh.', '.$st_year_sh?> 00:00:00'), //line 88 
      maxDate: new Date('<?php echo $en_date_sh.' '.$en_month_sh.', '.$en_year_sh?> 12:00:00'), //line 88   
      showOn: "button", 
      buttonImage: "images/Cal.gif", 
      buttonImageOnly: true, 
      /*beforeShowDay:function(dt){ 
       return [(dt.getDay()==0)?false:true]; 
      },*/ 
      onSelect: function(dateText, inst) { 
       var dt_txt = dateText.replace('-','/'); 
       dt_txt = dt_txt.replace('-','/'); 
       var tmp_dt = new Date(dt_txt); 
       if(tmp_dt.getDay()==0) 
       { 
        if(confirm("Are you certain you want to assign Sunday delivery date?")) 
        { 
         //$(this).closest("tr").find(".update_quote_row").click(); 
        } 
        else 
        { 
         return false; 
        } 
       } 
      } 

     }); 

我想要做的是,如果用戶試圖選擇一個星期日,則應該顯示確認,並且只有在確認選擇後纔會填充關聯的文本框。但是,使用我的代碼,無論我確認還是取消,文本字段都會更改爲所選值,並且我需要阻止該字段。我不能簡單地將輸入字段設置爲空白,因爲如果用戶取消確認,可能存在不應該修改的現有值。如何防止填充文本字段的jquery ui datepicker?

回答

0

這裏有一個想法:

1. Assign your datepicker to a div. See 'Display inline' example in http://jqueryui.com/demos/datepicker/#inline 
2. onclick of the input field, show the div. Make sure you copy the date (if present) in the input field to the datepicker div before show 
3. Then you can select your date accordingly and the date in the input field would not change. 
4. After getting your required date, click the submit button and assign the date on the datepicker to the input field and hide the div. 
0

您可以文本框的前值存儲在某個變量,並相應的工作,如:

var prevVal = $.trim($("input.datepicker_1").val()); 
$(".datepicker_1").datepicker({ 
    numberOfMonths: 2, 
    showButtonPanel: false, 
    ...... 
    onSelect: function(dateText, inst) { 
     var dt_txt = dateText.replace('-','/'); 
     dt_txt = dt_txt.replace('-','/'); 
     var tmp_dt = new Date(dt_txt); 
     if(tmp_dt.getDay()==0) { 
      if(confirm("Are you certain you wa...")) { 
       return true; 
      } 
      else { 
       //show previous value 
       $(".datepicker_1").val(prevVal); 
      } 
      ......... 

希望它可以幫助

相關問題