3

I'm trying to use https://github.com/HubSpot/vex modal script for a confirm-dialog. At the moment, if the confirm dialog box appeares, the "ok"-button is selected as default. Do anybody know how i can change this? I'd like the the cancel-button is for default so that anybody hit just enter, nothing happens.

thanks for your answer.

best regards thomas

1
  • Post your html and JavaScript
    – n1k1ch
    Feb 17, 2014 at 20:24

2 Answers 2

8

set the text of the buttons in your array

vex.dialog.open({          
    message: 'Are you absolutely sure you want to destroy the alien planet?', 
    overlayClosesOnClick: false, // set false to click out
    callback: function (value) {
        console.log(value);
    },
    buttons: [
        $.extend({}, vex.dialog.buttons.YES, { text: 'Your Button For Yesy' }),
        $.extend({}, vex.dialog.buttons.NO, { text: 'Your Button For No' })
    ]
 });
2
  • Thanks for your answer. This works good inside the dialog-box, but if i klick outside it makes the action for the wrong button (formally cancel, now ok) how can i change this as well? Feb 19, 2014 at 14:28
  • I edited my question. set overlayClosesOnClick false to disable click out Feb 19, 2014 at 16:12
1

To modify this as default behaviour, change the order of the buttons and class name in the vex JavaScript file. (vex.combined.js)

This will make the 'Cancel' button the default button.

dialog.buttons = { 
        NO: {
          text: 'Cancel',
          type: 'button',
          className: 'vex-dialog-button-primary',
          click: function noClick () {
            this.value = false
            this.close()
          }
        },
        YES: {
          text: 'OK',
          type: 'submit',
          className: 'vex-dialog-button-secondary',
          click: function yesClick () {
            this.value = true
          }
        }
}

dialog.defaultOptions = {
    ..
    buttons: [
      dialog.buttons.NO,
      dialog.buttons.YES
    ],
    ..
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.