简体   繁体   English

如何在 Tempus Dominus datetimepicker 中修复“未捕获的类型错误:无法读取未定义的属性‘格式’”?

[英]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?如何修复错误?

My Demo我的演示

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() 错误修复步骤

  1. unmin file tempusdominus-bootstrap-4.min.js unmin 文件 tempusdominus-bootstrap-4.min.js
  2. find _getLastPickedDate()找到 _getLastPickedDate()
  3. replace with 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.

相关问题 未捕获的TypeError:无法读取未定义的属性“格式” - Uncaught TypeError: Cannot read property 'format' of undefined 如何修复未捕获的类型错误:无法读取未定义的属性“名称” - How to fix Uncaught TypeError: Cannot read property 'name' of undefined 如何解决“未捕获的TypeError:无法读取未定义的属性'Timestamp'”? - How to fix “Uncaught TypeError: Cannot read property 'Timestamp' of undefined”? 如何修复Uncaught TypeError:无法读取undefined的属性'settings' - How to fix Uncaught TypeError: Cannot read property 'settings' of undefined 如何修复Uncaught TypeError:无法读取Dygraphs中未定义的属性'pageX'? - How to fix Uncaught TypeError: Cannot read property 'pageX' of undefined in Dygraphs? 如何解决“未捕获的TypeError:无法读取未定义的属性'number'”? - How to fix “Uncaught TypeError: Cannot read property 'number' of undefined”? 如何修复“Uncaught TypeError: Cannot read property 'scrollHeight' of undefined”错误 - how to fix “Uncaught TypeError: Cannot read property 'scrollHeight' of undefined” error 如何修复未捕获的类型错误:无法读取未定义的属性“原型”? - How to fix Uncaught TypeError: Cannot read property 'prototype' of undefined? 如何修复“未捕获的类型错误:无法读取未定义的属性‘替换’”错误? - How to fix "Uncaught TypeError: Cannot read property 'replace' of undefined" error? 如何修复'Uncaught TypeError:无法读取未定义的属性'length' - How to fix 'Uncaught TypeError: Cannot read property 'length' of undefined'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM