在jqgrid的自定义形式上的beforeSubmit事件到自定义按钮不起作用 [英] beforeSubmit event to custom button on a custom form of jqgrid doesn't work

查看:308
本文介绍了在jqgrid的自定义形式上的beforeSubmit事件到自定义按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将jqgrid 4.5.2版本与Jquery-3.2.1.一起使用

I am using jqgrid 4.5.2 version with Jquery-3.2.1.

在jqgrid中,代替了编辑按钮(添加,编辑和删除),实现了自定义(添加,编辑和删除)按钮.现在,单击自定义添加/编辑按钮,将打开一个自定义表单.以下是自定义按钮的onclick事件.

In jqgrid, in place of edit buttons (add, edit and delete) custom (add, edit and delete) buttons are implemented. Now on clicking the custom add/edit buttons a custom form is opened. The below is the onclick event for the custom buttons.

这意味着我们用自己的自定义表单替换了jqgrid默认的编辑/添加表单.早些时候,我们使用beforeSubmit事件编写了一些验证,这些验证与jqgrid的默认(添加/编辑)形式一起正常工作.现在,我想对替换后的自定义表单应用相同的验证.

That means we replaced the jqgrid default edit/add forms with our own custom forms. Earlier we wrote some validations with beforeSubmit event which were working fine with default(add/edit) forms of jqgrid. Now I want to apply the same validations to the replaced custom forms.

function(myGrid){
  myGrid.getGridParam('dataGrid').openEditFormIndicator();
}(myGrid)

该自定义表单具有自定义的提交和取消按钮.现在,我想在此提交按钮中添加beforeSubmit事件.由于表单是自定义的,因此jqgrids默认的beforeSubmit事件不起作用.

That custom form has custom submit and cancel buttons. Now I would like to add beforeSubmit event to this submit button. As the form is custom, jqgrids default beforeSubmit event doesn't work.

添加/编辑表单由我们自己的基于Java的框架构建.表格完全独立于jqgrid.我只是从jqgrid行(双击或单击编辑按钮)获取ID,并将其传递给模板,该模板从db中提取数据并形成行编辑表单.如果传递的id为空或在db上找不到,则使用相同的模板形成一个空的(添加)表单.

Add/Edit forms are built by our own framework which is built on Java. The forms are completely independent of jqgrid. I just get the id from jqgrid row (on double click or clicking on edit button) and pass it to a template, which pulls the data from db and forms the row edit form. If the id passed is empty or didn't find on db, an empty (add)form is formed with the same template.

DataGrid.prototype.openEditFormIndicator = function() {
var id = this.grid.getGridParam('selrow')
if(!id) {
    var gridId = this.grid.attr('id');
    var idSelector = "#alertmod_" + gridId;
    $.jgrid.viewModal(idSelector, {
        gbox: "#gbox_" + $.jgrid.jqID(gridId),
        jqm: true
    });
    $(idSelector).find(".ui-jqdialog-titlebar-close").focus();
}
else {
    //openInteractiveForm('form_plugin_examples',this.options.formIndicatorId,'id',id,'true'); 
    var encodedPkId = encodeURIComponent(id);
    this.openFormIndicator('Id:' + encodedPkId + ',pkId:' + encodedPkId + ',Search:id%3A' + encodedPkId + ',IndicatorId:' + this.options.formIndicatorId + ',Debug:true' + ',FilterField:id,FilterValue:' + encodedPkId);
    // TODO width, length, position
}
};

DataGrid.prototype.openFormIndicator = function(optionsStr) {
  DialogBoxEdit.newWindow(this.options.formIndicatorId, optionsStr);
};

使用以上两个功能,在DialogBoxEditHandler.js中形成添加/编辑表单. js内部调用一个模板来创建表单.

With the above two functions, the add/edit form is formed in DialogBoxEditHandler.js. The js internally calls a template to create the form.

创建的表单包含以下两个按钮,我需要为其添加beforeSubmit事件.

The created form contains the below two buttons, for which I need to add beforeSubmit event.

<Button id="lnk-close" onclick="closeDialogBoxControl($(this).closest('form'));" class="btn-default">Close</Button>
<Button id="lnk-submit" onclick="save_form_data($(this).closest('form'),true,'72');MD.ui.reloadGrid();"  class="btn-primary ui-dialog-close">Save</Button>

推荐答案

似乎您第二次提出了这个问题. 此处是

It seems you put this question second time. The documenatation for this is here

基本上,在这种情况下,您将需要定义该事件并返回适当的数组.当您单击onclick事件中定义的自定义按钮时,使用链接中提供的帮助,您可以执行以下操作:

Basically in this case you will need to define that event and return the appropriate array. Using the help provided in the link when you click the custom button defined in a onclick event you can do this:

...
jQuery("#grid_id").jqGrid('editGridRow', rowid, {
    ...
    beforeSubmit : function( postdata, formid ) {
        if(someconditionOK) {
            return [true,''];
        } else {
            return [false,'Error submiting data'];
        }
    },
    ...
});

这篇关于在jqgrid的自定义形式上的beforeSubmit事件到自定义按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆