0

I'm having a strange issue that I've never encountered before.

I have a partial view that contains additional buttons for the page it's called from, which are simply:

<button id="editorApproveBtn" name="submitBtn" value="EditorAppove">Approve</button>
<button id="editorDenyBtn" name="submitBtn" value="EditorDeny">Deny</button>

These are additions to other buttons on the page called the same thing.

The other buttons are used for simple submits - saving the form content in 2 different ways, but these two bring up a jQuery Dialog, however, the dialogs show fine, but the form instantly submits when they've loaded.

Here's my dialog code:

$('#editorApproveBtn').button().click(function () {
        $("#confirmApproveDialog").dialog({
            bgiframe: true,
            height: 200,
            modal: true,
            resizable: false,
            width: 400,
            buttons: {
                'Yes': function () {
                    $(this).submit();
                    return false
                },
                'No': function () { $(this).dialog("close"); }
            }
        });
    });

I've not a clue what's going on, I've never seen or heard of this behaviour with it before.

Has anyone else had this issue or know of a way to fix it? or have I made a mistake and it's caused it?

Thanks in advance for any help.

1 Answer 1

4

Try adding return false; to the end of the .click() callback function. In some browsers, button elements submit the page.

Like this:

$('#editorApproveBtn').button().click(function () {
    $("#confirmApproveDialog").dialog({
        bgiframe: true,
        height: 200,
        modal: true,
        resizable: false,
        width: 400,
        buttons: {
            'Yes': function () {
                $(this).submit();
                return false
            },
            'No': function () { $(this).dialog("close"); }
        }
    });
    return false;
});
Sign up to request clarification or add additional context in comments.

5 Comments

Bah, I knew it must've been something stupidly simple like that. Thanks for the help!
Though as a side note, I haven't had to do this on any other dialog's around the application?
Well I've had the opportunity to test it properly now I'm back at my work machine, but I'm having a small issue where clicking the 'Yes' button doesn't actually do anything now with the return false; at the end of .click();. Is there a way around this?
@Liam: What is it supposed to be submitting? A form on your page? It looks like you're trying to run .submit() on the dialog. Are you sure you have the right selector ($(this))?
Ah it was a mistake on my part, I assumed that this would automatically refer to the form, but it doesn't it refers to the dialog box. I changed it to #EditPageForm and all is well. It's been a long day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.