0
votes

I have a bootbox confirm dialog box. In that, I have some form validation.Validation working fine and as long as validation fails confirm dialog box still opens. But when I click on the cancel button, still it is asking for validation.

bootbox.confirm({ 
    closeButton: true,
    message: valid_result,
    size: 'large',
    title: 'Fill fields with related values',
     buttons    : {
     confirm : { label: '<i class="fa fa-check"></i> Validate'}
    }, 

      callback: function () {                  
           var res =  getLinkupInformation(ids_string)
            if(res == true) {
              return true;
            } else {
              return false;
            }

      }
  });

The validation part is working and if validation passed then only modal was closing. But when user click on the cancel button or close icon still it is asking validation. When I remove return false in call back function in else part then the validation button is not working and when I click on the validate button confirmation dialog box was closing.
Please guide me how to solve this issue?

1

1 Answers

0
votes

The callback expects you to supply an argument, like so:

callback: function (result) {

}

If the user cancelled the dialog, either by clicking Cancel or the close (x) button, then result (or whatever you called your argument) will be the value false. You would use that value like this:

callback: function (result) {
    if(result) {
        /* your code here */
    }
}

This is more or less covered in the documentation.