我的日期选择工作正常,直到我更改日期。更改显示的日期后: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);
});
}
图像显示控制台日志和错误。我不确定&#34; yyyy-MM-dd&#34;来自,因为我从来没有分配它或在$value
以外的任何地方使用它,但这对value
来说是必要的,否则当我尝试用Jquery获取值日期时我得到NaN。