开发者

jQuery Remote Validation Forces Double-Click to Submit Form

I am attempting to validate a form f开发者_运维百科ield remotely. If the field receives focus while I'm on the page, everything works great. However, if the field never receives focus, the form requires I click the "Submit" button twice in order to successfully submit.

I'd like it to either only validate if the field receives focus or somehow stop the form from requiring two clicks to submit. Anyone have any ideas?

$("#form1").validate({
    rules: {
        project: {
            required: true,
            remote: "check.php"
        }
    },
    messages: {
        project: {
            required: "Required.",
            remote: "Check Failed."
        }
    },
});

<input type="text" name="project" id="project" value="X"/>


Instead of making ajax setup to false you can just set "project" "remote" async to false like this

$("#form1").validate({
    rules: {
        project: {
            required: true,
            remote: {url:"check.php", async:false}
        }
    },
    messages: {
        project: {
            required: "Required.",
            remote: "Check Failed."
        }
    },
});


What is the name of your submit button? jQuery Validate doesn't like the name "submit." I changed the name of my submit button to "submitter," and the problem went away. Check out this link: https://github.com/jzaefferer/jquery-validation/issues/58


You can resolve the problem by adding:

$.ajaxSetup({
    async: false
});

Before you call the validation plugin.


I was having the same issue and remote: {url:"check.php", async:false} worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜