开发者

JQGrid clicking ENTER on EDIT popup

I have a form that i use in jqgrid in add/edit popup

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id = "formId" }))
{
//...
}

When i click a row that form opens. If i press the textbox and click ENTER this form submits. And it submits as a regular post request, not by using jqgrid. But if i click on the Save button it works as required.

buttons: {
                    'Save': function () {

                        if ($('#formId').valid()) {

                            $.ajax({
                                type: 'POST',
                                url: '@Url.Action( "Action", "Cont开发者_StackOverflow中文版roller" )',
                                data: $('#formId').serialize(),
                                success: function (json) {
                                    $("#grid").trigger("reloadGrid");
                                },
                                error: function (e) {
                                    alert("Unable to save." + e);
                                },
                                dataType: "application/JSON"
                            });

                            $("#divForm").dialog('close');
                        }
                    },

But i want that when i click ENTER that will be as the save button click.


Try subscribing for the submit event of the form:

<div id="formContainer">
    @using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id = "formId" }))
    {
        ...
    }
</div>

and then:

$('#formContainer').delegate('#formId', 'submit', function (evt) {
    evt.preventDefault();
    if ($(this).valid()) {
        $.ajax({
            type: this.method,
            url: this.action,
            data: $(this).serialize(),
            success: function (json) {
                $('#grid').trigger("reloadGrid");
            },
            error: function (e) {
                alert("Unable to save." + e);
            },
        });
    }
});

and now in the Save button click force the form submission:

'Save': function () {
    $('#formId').submit();
}

but probably it would be better to use the form's submit button to submit a form.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜