简体   繁体   English

rome.js知道用户何时完成

[英]rome.js knowing when the user is finished

I am using rome.js for a date picker. 我正在使用rome.js作为日期选择器。 When the user is finished enter the date, I need the date picker to go away and be replaced on the page by text showing the date. 当用户输入完日期后,我需要离开日期选择器,并在页面上将其替换为显示日期的文本。 The problem is, I'm not sure how to tell when the user is done picking the date. 问题是,我不确定如何确定用户何时选择日期。 I don't really want to have to add another control for them to put away the date picker, but would like to infer this from the user's actions. 我并不是真的要为他们添加另一个控件来放置日期选择器,而是想从用户的操作中推断出这一点。

One thought I had was to look for the hide event - when coupled with autoHideOnClick and autoHideOnBlur I thought I could tell that the user had entered a new date and was done. 我曾经想过要查找hide事件-与autoHideOnClickautoHideOnBlur结合使用时,我以为我可以告诉用户输入了一个新日期并完成了操作。 However, what I find is that I immediately get this event as soon as the picker is created - even if the input element has focus when I create the picker, the picker doesn't pop up immediately. 但是,我发现,创建选择器后,我会立即获得此事件-即使在创建选择器时输入元素具有焦点,选择器也不会立即弹出。 In addition, the hide event sometimes happens even when the user is still enter the date, such as if they enter the date and then want to still enter the time manually. 此外,即使用户仍在输入日期(例如,他们输入日期然后想要手动输入时间),有时也会发生隐藏事件。

I had similar issues with the blur event on the input element I create - for instance it fires when the picker is opened . 我在创建的输入元素上的blur事件也遇到了类似的问题,例如, 打开选择器时将触发该事件。

How am I supposed to know when the user has finished enter the date/time? 我应该如何知道用户何时输入日期/时间?

I think you could add a keydown event handler to the date input and on each keydown stroke, validate the date and if it's valid one change the display property of the date-picker (class name is rd-container) to "none". 我认为您可以在日期输入中添加一个keydown事件处理程序,并在每个keydown笔划上验证日期,如果有效,则将date-picker(类名称为rd-container)的display属性更改为“ none”。

Here is the pseudo code. 这是伪代码。 I verfied on https://www.cssscript.com/demo/highly-customizable-date-and-time-picker-with-rome-js/ 我在https://www.cssscript.com/demo/highly-customizable-date-and-time-picker-with-rome-js/上进行了验证

dateInput.onkeydown = function () {
   if(dateInput.text is valid) { //validate the date here.
     $(".rd-container").css("display","none");
   }
}

you can use the same function to detect if user "pastes" date text into your input element by listening to "onpaste" event. 您可以使用相同的功能通过侦听“ onpaste”事件来检测用户是否将日期文本“粘贴”到输入元素中。

dateInput.onpaste = function () {
   if(dateInput.text is valid) { //validate the date here.
     $(".rd-container").css("display","none");
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM