2017-05-08 133 views
1

我的日期選擇器正常工作,直到我更改日期。我更改日期後,它表明:The specified value "24-05-2017" does not conform to the required format, "yyyy-MM-dd".更改日期選擇器UI日期會給出錯誤

Smarty的HTML:

{assign var="value" value=$value|date_format:'%Y-%m-%d'} 
<div class="select{if $value === '1000-01-01' || $value|substr:0:4 === '1000'} no-date{/if}"> 
    {assign var="dateFormat" value="dd-mm-yy"} 
    <div class='input-group date'> 
     <input type='date' class="form-control {if $value === '1000-01-01' || $value|substr:0:4 === '1000'}no-date{/if}" name="{$name|escape}" id="edit-{$name|escape}"{if $value} value="{$value|escape}" placeholder="{$value|escape}" 
       data-role="datepicker" data-date-format="{$dateFormat|escape}"> 
    </div> 
</div> 

的Jquery:

self.datepicker = function() 
{ 
    if (typeof jQuery.ui !== 'undefined') 
    { 
     $('[data-role="datepicker"]').each(function() 
     { 
      var $this = $(this); 
      var date = new Date($this.val()); 
      date = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); 

      console.log(date); 
      var defaults = { 
       showButtonPanel: true, 
       dateFormat: $this.data('date-format'), 
       defaultDate: date === '1-1-1000' ? null : date, 
       showOtherMonths: true, 
       selectOtherMonths: true, 
       changeMonth: true, 
       changeYear: true, 
       yearRange: 'c-10:c+10' 
      }; 

      var options = $.extend({}, defaults, $this.data('options')); 

      console.log(options); 
      $this.datepicker(options); 
     }); 
    } 

結果: enter image description here

的圖像顯示在控制檯日誌和錯誤。我不確定「yyyy-MM-dd」來自哪裏,因爲我從未分配過它或在$value以外的任何地方使用過,但這是value必需的,否則當我嘗試獲取價值日期時jQuery的。

回答

2

設置的DateFormat到:

dateFormat: "dd-MM-yyyy" 
相關問題