GWT DateBox-禁用特定日期
我想在日期框中禁用特定日期。我使用此代码尝试了此操作,但是指定的日期(当日)没有被禁用。
I want to disable a specific date in my date box. I tried it with this code, but the specified date (current day) does not get disabled.
final DateBox dateBox = new DateBox();
dateBox.getDatePicker().addShowRangeHandler(new ShowRangeHandler<Date>() {
@Override
public void onShowRange(final ShowRangeEvent<Date> event) {
List<Date> disabledDates = new ArrayList<Date>();
disabledDates.add(new Date());
dateBox.getDatePicker().setTransientEnabledOnDates(false, disabledDates);
}
});
还有其他方法吗?
编辑:按照apanizo的示例,当天29.5看起来是灰色的,但是仍然可以单击。
Following the example of apanizo, the day 29.5 looks greyed out, but is clickable nevertheless.
真的很抱歉,我没有测试我的最后一个答案的代码。
Really sorry, I did not test the code of my last answer.
我刚刚尝试了并且您的代码对我有效,我唯一要做的就是通过所有通过 setTransientEnabledOnDates(false,dateToDisable);
方法不需要的日期。
I have just tried and your code worked to me, the only thing that I did was pass all the dates that I do not want through the setTransientEnabledOnDates(false, dateToDisable);
method.
示例:
public void onModuleLoad() {
final DateBox dateBox = new DateBox();
dateBox.getDatePicker().addShowRangeHandler(new ShowRangeHandler<Date>() {
@Override
public void onShowRange(final ShowRangeEvent<Date> dateShowRangeEvent) {
final Date today = new Date(); //30 May 3014
final Date yesterday = new Date(today.getTime()- 24*60*60*1000);
//disabling yesterday - 29 May of 2014
dateBox.getDatePicker().setTransientEnabledOnDates(false, yesterday);
}
});
RootPanel.get().add(dateBox);
}
如果要在禁用日期禁用单击事件,这是一个已解决但尚未交付的错误。
If you want to disable the click event on a disabled date, this is a resolved and not delivered bug.
请参阅:
https://code.google.com/p/google-web-toolkit/issues/detail?id=7876
我认为它将在GWT 2.7版本中发布,与此同时,您可以在 com.google.gwt.user.datepicker的第77行中对其进行修补。 .client.CellGridImpl
:
I think in the GWT's 2.7 version it will be released, in the mean time you can patch it introducing in the line 77 of com.google.gwt.user.datepicker.client.CellGridImpl
:
addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (isActive(Cell.this)) {
setSelected(Cell.this);
}
}
}, ClickEvent.getType());
在详细信息