I'm using a DatePicker widget, and I put a little calendar image next to it. When you click on the actual DatePicker textbox, the calendar popup pops up 开发者_如何学Go(as it should). I'm looking to add this click handling to the little calendar image too, so that the user can click either the box or the image to see the calendar popup. Is there an easy way to do this?
I thought it might be something like this:
calendarImage.addClickHandler(datePick.getTextBox().getClickHandler())
But it doesn't seem that anything like this exists.
Thanks in advance!
Just add a clickhandler to the image that sets the datepicker visible.
It will become something like this:
private DatePicker datePicker = new DatePicker();
private TextBox textBox = new TextBox();
private Image icon = new Image("calendar.png");
public void onModuleLoad() {
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(ValueChangeEvent<Date> event) {
Date date = event.getValue();
String dateStr = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM).format(date);
textBox.setText(dateStr);
datePicker.setVisible(false);
}
});
datePicker.setVisible(false);
icon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
datePicker.setVisible(true);
}
});
RootPanel.get().add(icon);
RootPanel.get().add(textBox);
RootPanel.get().add(datePicker);
}
Assuming you mean DateBox when you write DatePicker, simply call showDatePicker on click of the icon (and/or test isDatePickerShowing and call hideDatePicker)
加载中,请稍侯......
精彩评论