javascript - AngularUI Bootstrap Datepicker 日期取消选择

标签 javascript angularjs datepicker angular-ui

我正在使用UI-Bootstrap Datepicker内联日期选择,如下所示。

<datepicker ng-model="profile.available_from" show-weeks="true"></datepicker>

我想让用户通过再次单击同一日期来取消选择当前选定的日期。

例如。用户点击 2015 年 5 月 29 日,相应的图 block 会突出显示,并且 profile.available_from 会使用该值进行更新。如果用户现在再次单击同一日期,则应删除选择突出显示,并将 profile.available_from 设置为 undefined/null。

有什么想法吗?

最佳答案

我想如果不修改datepicker的原始源代码这是不可能的。 它必须检查该字段是否已经具有选定的值,如果是,则清除它。这会使代码变得复杂,而且没有明显的好处。

我会添加清除按钮。

示例代码(取自 http://angular-ui.github.io/bootstrap/#/datepicker )

$scope.clear = function () {
  $scope.profile.available_from = null;
};

关于javascript - AngularUI Bootstrap Datepicker 日期取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27798682/

相关文章:

javascript - WordPress add_option 查询返回空白参数

angularjs - 大型 AngularJS 应用程序 - 多种 UI 布局

list - 您如何获得像闹钟中显示的那种列表选择器?

javascript - 将类添加到日期选择器选择

javascript - 需要内联日期、月份和年份选择标签

javascript - 如何通过名称调用函数并作为参数传递?

javascript - Angular 2 - 如何在 addEventListener 处理函数中调用 typescript 函数?

javascript - 我如何包含模型数组?

javascript - AngularJS 与 TypeScript 未捕获错误 : [$injector:modulerr]

javascript - 打开从 html 表导出的 xls 文件时出现警告