anjanb
anjanb

Reputation: 13927

dojo 1.4 blocking yes/no dialog replacement for window.confirm

I am stuck in dojo 1.4.
Need a synchronous (blocking) dialog replacement for window.confirm().
why : I would like the buttons to be YES/NO instead of OK/CANCEL.
This dialog will be called from multiple parts of the app -- so needs proper cleanup. Is there a dojo library that has this functionality ?
I would prefer all dynamic code so I can include this new dialog from within a .js file or a html/jsp file but something working is appreciated.

Upvotes: 1

Views: 1882

Answers (1)

phusick
phusick

Reputation: 7352

You cannot make it synchronous, but you can prevent the form from submitting by event.preventDefault() or onsubmit="return false;" as @FakeRainBrigand mentioned.

Here is a working example: http://jsfiddle.net/phusick/73PuE/.

enter image description here

It employs the confirm dialog I mentioned in the comment above. It is written in Dojo 1.8, but it should be more or less the same as in 1.4, just use dojo.connet instead of dojo/on:

var form1 = dom.byId("form1");

on(form1, "submit", function(event) {
    event.preventDefault();
    var form = event.target;
    MessageBox.confirm({ message: "Submit form?" }).then(function() {
        // submit the form upon a click on `Yes`
        form.submit();
    });        
});

You can achieve the same in plain vanilla JavaScript:

function confirmHandler(event) {
    event.preventDefault();

    var form = event.target;
    // ask for a confirmation and if confirmed invoke:
    // form.submit();
}

Register handler on the form:

<form onsubmit="confirmHandler(event);">

Upvotes: 1

Related Questions