我有 4 个标签。我想阻止用户(使用 window.alert 示例)进入另一个选项卡,因为它尚未完成填充当前选项卡。用户填写完所有字段后,当前选项卡内会出现一个文本(说他可以移动到下一个选项卡)。他将能够单击下面的选项卡。
我应该使用 BeforeSelectionEvent 处理程序还是 SelectionHandler?
我做这个代码来回答我的问题,但太长了
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.");
}
}
}
});
对于 GWT 选项卡面板:
@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;
}
}