4

I have a UI like this

enter image description here

which uses com.extjs.gxt.ui.client.widget.form.DateField On "change" event of Date i have a listener. 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 )

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 ??

Lav
  • 1,283
  • 5
  • 21
  • 48

3 Answers3

6

i think you apply listener on datefield.you have to apply listener on datepicker as follow

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.

Divyesh Rupawala
  • 1,221
  • 8
  • 15
  • Thanks for the help , but this did not work **// OLD CODE** 'date.addListener(Events.Change, new Listener() { public void handleEvent(FieldEvent be) { System.out.println("Selected Date : "+be.getValue()); } });' // NEW CODE date.getDatePicker().addListener(Events.Select, new Listener() { public void handleEvent(DatePickerEvent be) { System.out.println("Selected Date : "+be.getDate()); } }); – Lav Jun 17 '13 at 05:28
  • @Lav It worked like a charm. Have you tried something like `ValueChangeEvent.fire(dateField, event.getValue());` inside `handleEvent` method? – Stelios Adamantidis Oct 17 '16 at 10:18
0

An easy way to solve the problem is registering ClickEvent for the dateField, dateTextBox in this example:

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.

manfontan
  • 11
  • 3
0

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).

El Hoss
  • 3,767
  • 2
  • 18
  • 24