2017-05-08 5 views
1

Mein Datepicker funktioniert gut, bis ich das Datum ändere. Nachdem ich das Datum ändern es zeigt: The specified value "24-05-2017" does not conform to the required format, "yyyy-MM-dd".Das Ändern des Datepicker-UI-Datums führt zu einem Fehler

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); 
     }); 
    } 

Ergebnisse: enter image description here

Das Bild zeigt die Konsolenprotokolle und den Fehler. Ich bin mir nicht sicher, woher das "JJJJ-MM-TT" kommt, denn ich habe es nie zugewiesen oder benutzt es außer $value, aber das ist notwendig für value sonst bekomme ich NaN, wenn ich versuche, das Valutadatum zu bekommen Jquery.

Antwort

2

Stellen Sie das Datumsformat an:

dateFormat: "dd-MM-yyyy" 
Verwandte Themen