【问题标题】:Invalid Date Error when the max-Date is cleared清除 max-Date 时出现无效日期错误
【发布时间】:2019-09-21 15:34:28
【问题描述】:

我有两个输入字段,它们是日期选择器“startDate”和“endDate”。对于 startDate,最大日期应该是 endDate。对于 endDate,最小日期应该是 startDate。当我清除 startDate 并尝试为 endDate 设置新日期时,它给出“无效日期错误”,因为 min-Date(StartDate) 值已清除。请帮我解决这个问题

<div class="col l2 m4 s12 input-field">
    <input id="startDate" type="text" ng-model="startDate" date-picker="date" format="D/M/YYYY" max-date="endDate" />
    <label material-active="startDate" for="startDate">Min. Created Date</label>
    <a class="clear-button" href="#" ng-click="clearDate($event, 'startDate')" ng-show="startDate">X</a>
</div>
<div class="col l2 m4 s12 input-field">
    <input id="endDate" type="text" ng-model="endDate" date-picker="date" format="D/M/YYYY" min-date="startDate" />
    <label material-active="endDate" for="endDate">Max. Created Date</label>
    <a class="clear-button" href="#" ng-click="clearDate($event, 'endDate')" ng-show="endDate">X</a>
</div>


scope.clearDate = function (e, prop) {
                            e.preventDefault();
                            scope[prop] = '';
                        }

【问题讨论】:

  • 您可以为字段添加 onChange 侦听器并使用几行 javascript 进行验证,以便您可以检查空值。

标签: javascript c# html


【解决方案1】:

请检查您的日期格式值,format="D/M/YYYY" 试试format="dd/MM/yyyy"

【讨论】:

  • 我尝试了这个解决方案,但问题仍然存在。我正在使用 bootstrapMaterialDatePicker
猜你喜欢
  • 2020-12-07
  • 2016-09-06
  • 1970-01-01
  • 2023-03-10
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
相关资源
最近更新 更多