【问题标题】:Changing datepicker UI date gives error更改 datepicker UI 日期会出错
【发布时间】:2017-10-06 03:57:09
【问题描述】:

在我更改日期之前,我的日期选择器工作正常。在我更改它显示的日期后:The specified value "24-05-2017" does not conform to the required format, "yyyy-MM-dd".

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

结果:

图像显示控制台日志和错误。我不确定“yyyy-MM-dd”是从哪里来的,因为除了$value 之外,我从未分配或使用过它,但这对于value 来说是必要的,否则当我尝试获取时我会得到NaN Jquery 的生效日期。

【问题讨论】:

    标签: jquery jquery-ui datepicker smarty uidatepicker


    【解决方案1】:

    将日期格式设置为:

    dateFormat: "dd-MM-yyyy"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多