[英]How to fix "Uncaught TypeError: Cannot read property 'format' of undefined" at Tempus Dominus datetimepicker?
I have used Tempus Dominus Bootstrap 4 for my date time picker.我使用Tempus Dominus Bootstrap 4作为我的日期时间选择器。 When user put invalid value on the input and focus out(click outside of the component), it gets Uncaught TypeError: Cannot read property 'format' of undefined
.当用户在输入上输入无效值并聚焦(单击组件外部)时,它会得到Uncaught TypeError: Cannot read property 'format' of undefined
。
But, expected behavior is like this: https://i.imgur.com/MWgrBkB.mp4但是,预期的行为是这样的: https ://i.imgur.com/MWgrBkB.mp4
How to fix the error?如何修复错误?
Update: Issue wasn't generated for someone.更新:没有为某人生成问题。 Here is the way of generating the issue: https://i.imgur.com/F0BpgZQ.mp4这是产生问题的方式: https ://i.imgur.com/F0BpgZQ.mp4
You can try this你可以试试这个
$('.date-time-picker').datetimepicker
({
format:'DD-MM-YYYY hh:mm',
icons:{
time:'far fa-clock'
}
})
If somebody face a similar issue take into account if you are initializing, set option, or get option from the datepicker:如果有人遇到类似问题,请考虑您是在初始化、设置选项还是从日期选择器获取选项:
https://tempusdominus.github.io/bootstrap-4/Options/ https://tempusdominus.github.io/bootstrap-4/Options/
Note Initialize options as $('#datetimepicker').datetimepicker({ sideBySide: true, debug: true })
注意初始化选项为$('#datetimepicker').datetimepicker({ sideBySide: true, debug: true })
Note To set options use $('#datetimepicker').datetimepicker('sideBySide', true)
注意要设置选项使用$('#datetimepicker').datetimepicker('sideBySide', true)
Note To get option value use $('#datetimepicker').datetimepicker('sideBySide')
注意要获取选项值,请使用$('#datetimepicker').datetimepicker('sideBySide')
In my case I was initializing the defaults icons in a common js file and initializing again (Initialize option) in a local js of the page.在我的情况下,我正在一个公共 js 文件中初始化默认图标,并在页面的本地 js 中再次初始化(初始化选项)。 In the local js set options method should be used.在本地 js 中应该使用 set options 方法。
this Fix from github , it error from function _getLastPickedDate() in file tempusdominus-bootstrap-4.min.js step to fix这个来自 github 的修复,它来自文件 tempusdominus-bootstrap-4.min.js 中的函数 _getLastPickedDate() 错误修复步骤
var lastDate = this._dates[this._getLastPickedDateIndex()]; if (typeof lastDate == "undefined" || lastDate == null) { lastDate = this.getMoment(); } return lastDate;
替换为var lastDate = this._dates[this._getLastPickedDateIndex()]; if (typeof lastDate == "undefined" || lastDate == null) { lastDate = this.getMoment(); } return lastDate;
var lastDate = this._dates[this._getLastPickedDateIndex()]; if (typeof lastDate == "undefined" || lastDate == null) { lastDate = this.getMoment(); } return lastDate;
cr.铬。 github github
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.