简体   繁体   English

在GXT中为Date触发Change事件

[英]In GXT when is Change Event fired for Date

I have a UI like this 我有这样的UI

在此输入图像描述

which uses com.extjs.gxt.ui.client.widget.form.DateField On "change" event of Date i have a listener. 它使用com.extjs.gxt.ui.client.widget.form.DateField在Date的“change”事件中我有一个监听器。 The Issue here is 这里的问题是

  1. The "Change Event" is fired only when user changes date and then click outside ( somewhere in blank area of form ) 当用户更改日期然后单击外部 (表单的空白区域中的某处)时,才会触发“更改事件”
  2. If user just changes the date and doesn't click outside on form , the Change Event is not fired. 如果用户只更改日期并且未在表单上单击外部,则不会触发更改事件。
  3. I tried other events like Focus , Blur , Valid the issue with these is that date is coming as null ( and not new changed value ) i want to call my code only when the date value is changed ( without the user need to click outside ) 我尝试过像Focus,Blur这样的其他事件。这些问题的问题是日期是空的(而不是新的更改值)我想只在日期值改变时调用我的代码(用户不需要点击外部)

My question is i want to call my code only when the date value is changed without the user need to click outside... is there a way ?? 我的问题是我只想在更改日期值调用我的代码 而无需用户点击外面...有没有办法?

i think you apply listener on datefield.you have to apply listener on datepicker as follow 我认为你在datefield上应用监听器。你必须在datepicker上应用监听器 ,如下所示

DateField dateField = new DateField();
dateField.getDatePicker().addListener(Events.Select, new Listener<DatePickerEvent>() {

        @Override
        public void handleEvent(DatePickerEvent be) {
            System.out.println("Selected Date : "+be.getDate());
        }
});

i hope it will help you. 我希望它会对你有所帮助。

An easy way to solve the problem is registering ClickEvent for the dateField, dateTextBox in this example: 解决问题的一种简单方法是在此示例中为dateField,dateTextBox注册ClickEvent:

dateTextBox.addClickHandler(this);

Then fire the change event 然后解雇变更事件

public void onClick(ClickEvent event) {
    if (event.getSource().equals(datePicker)) {
        dateTextBox.setText(DateTimeFormat.getFormat(getDateFormat()).format(datePicker.getValue()));
        DomEvent.fireNativeEvent(Document.get().createChangeEvent(), dateTextBox);
        datePicker.hide();
      }
    }

The only thing with this aproach is that clicking on the year/mouth will hide the date picker. 这种方法的唯一之处在于点击年份/嘴将隐藏日期选择器。

As long as the user does not leave the widget, no blur-, focus, change-event will be fired. 只要用户不离开窗口小部件,就不会触发模糊,焦点,更改事件。 If you are interested in value changes, listen to the keyDown (onKeyDown) event and the TriggerEvent (onTriggerEvent). 如果您对值更改感兴趣,请侦听keyDown(onKeyDown)事件和TriggerEvent(onTriggerEvent)。

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

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