Reputation: 611
My datepicker works fine until I change the date. After I change the date it shows: The specified value "24-05-2017" does not conform to the required format, "yyyy-MM-dd".
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);
});
}
The image shows the console logs and the error. I'm not sure where the "yyyy-MM-dd" comes from, cause I have never assigned it or used it anywhere except for $value
, but that is neccesary for value
otherwise I get NaN when I try to get the value date with Jquery.
Upvotes: 1
Views: 1296