Lav
Lav

Reputation: 1313

In GXT when is Change Event fired for Date

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

Upvotes: 4

Views: 2878

Answers (3)

El Hoss
El Hoss

Reputation: 3832

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

Upvotes: 0

manfontan
manfontan

Reputation: 21

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.

Upvotes: 0

Divyesh Rupawala
Divyesh Rupawala

Reputation: 1221

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.

Upvotes: 6

Related Questions