我有4个标签。我想阻止用户(使用window.alert示例)获取另一个选项卡,因为它尚未填写当前选项卡。用户完成填写所有字段后,将在当前选项卡内显示一个文本(说他可以移动到下一个选项卡)。他可以点击下面的标签。
我应该使用BeforeSelectionEvent处理程序还是SelectionHandler?
答案 0 :(得分:1)
我执行此代码来回答我的问题但是太长了
is there a possibility to turn it into a short function ?
this.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
if (Application.get().getChampsObligatoire().values().contains("Fiche")) {
if (event.getItem().intValue() > 0){
event.cancel();
Window.alert("You must fill all fields before proceeding to the next step.");
}
}
if (Application.get().getChampsObligatoire().values().contains("projet")) {
if (event.getItem().intValue() > 1){
event.cancel();
Window.alert("You must fill all fields before proceeding to the next step.");
}
}
if (Application.get().getChampsObligatoire().values().contains("cibles")) {
if (event.getItem().intValue() > 2){
event.cancel();
Window.alert("You must fill all fields before proceeding to the next step.");
}
}
if (Application.get().getChampsObligatoire().values().contains("Ressources")) {
if (event.getItem().intValue() > 3){
event.cancel();
Window.alert("You must fill all fields before proceeding to the next step.");
}
}
if (Application.get().getChampsObligatoire().values().contains("Contrôle")) {
if (event.getItem().intValue() > 4){
event.cancel();
Window.alert("You must fill all fields before proceeding to the next step.");
}
}
}
});
答案 1 :(得分:0)
对于GWT TabPanel:
@Override
public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex)
{
String currentTabName = widget.getTabHTML(widget.getSelectedTab()); // for reference
String tabNameYouTryingToSelect = widget.getTabHTML(tabIndex); // for reference
// check some external self-written method and return true or false to allow/disallow selection
if (isCurrentlyActiveTabBuilt()){
return true;
} else {
Window.alert("You must fill all fields before proceeding to the next step.");
return false;
}
}