Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SC.ask setting focus to NO button by default

    Hi,

    I'm trying to build a modal dialog box where the user gets a confirmation message with a YES and a NO button. I'm using SC.ask for this purpose.

    Code:
    SC.ask("Do you want to proceed?", new BooleanCallback() {
    	public void execute(Boolean value) {
    		if(value) {
    			// YES, proceed with update
    			sendUpdateRequest(record);
    		}
    	}
    });
    The confirmation is displayed correctly, however the default focus is on the YES button.
    To ensure that the user does not skip through the confirmation by pressing Enter absentmindedly, I want to shift the default focus to the NO button.

    Can you please tell me how this can be done?

    Thanks

    #2
    I have not found a satisfactory answer yet. What you can do though is using the ask() method that accepts a Dialog.

    Code:
    Dialog dialog = new Dialog();
    dialog.setButtons(Dialog.NO, Dialog.YES);
    SC.ask(title, message, new BooleanCallback() {
    
      @Override
      public void execute(Boolean confirmation) {
        if (confirmation != null && confirmation.booleanValue()) {
          // do something
        }
      }
    }, dialog);
    Then if you invert the logical order of the buttons (note that Dialog.NO comes first) the NO button is focused :-/

    Comment


      #3
      After some more testing...

      This works but I hope there's something a little more elegant.
      Code:
      final Dialog dialog = new Dialog();
      Button yesButton = Dialog.YES;
      Button noButton = Dialog.NO;
      dialog.addButtonClickHandler(new ButtonClickHandler() {
      
        @Override
        public void onButtonClick(ButtonClickEvent event) {
          if (event.getIndex() == 0) {
            dialog.yesClick();
          } else {
            dialog.noClick();
          }
        }
      });
      dialog.setButtons(yesButton, noButton);
      SC.ask(title, message, new BooleanCallback() {
      
        @Override
        public void execute(Boolean confirmation) {
          if (confirmation != null && confirmation.booleanValue()) {
            // do something
          }
        }
      }, dialog);
      noButton.focus();

      Comment


        #4
        The docs do tell you to build your own Dialog if the built-in Dialog for ask(), warn() et al aren't what you want, and your code (based on the sample provided in the docs) is really pretty simple.

        Comment

        Working...
        X