0

I have 4 tabs. I want to prevent the user to get (with window.alert example) to another tab as it has not finished filling the current tab. After user finishes filling out all fields, a text will appear (saying he can move to the next tab) inside the current tab. And he will be able to click the tab below.

Should I use BeforeSelectionEvent handler or SelectionHandler?

alexp
  • 787
  • 5
  • 26
user978504
  • 11
  • 1

2 Answers2

1

i do this code to respond my question but is too long

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.");
                        }

                        }



              }

            }); 
user978504
  • 11
  • 1
0

For 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;
    }
}
alexp
  • 787
  • 5
  • 26
  • isCurrentlyActiveTabBuilt() is function or a variable ? – user978504 Oct 07 '12 at 15:50
  • This must be your custom method which defines the condition of completness. Smth, like: return field1.isChecked() && field2.isChecked && field3.value != null ... etc. – alexp Oct 08 '12 at 17:41