【发布时间】:2013-10-28 07:09:06
【问题描述】:
我想在jqgrid 中显示添加表单之前检查变量myVar 是否具有值。以下是我在添加选项中的代码,用于检查 myVar 是否具有价值。如果myVar 为空,那么我不想打开添加表单。
}).navGrid('#mypager',{cloneToTop:true, edit:false,add:true,del:false,view:false,search: false,refresh:true},
{},
{
beforeShowForm : function (formid)
{
if(myVar.length==0)
{
alert("Value can't be blank!");
return[false,"Value can't be blank!"];
}
},
recreateForm: true,
reloadAfterSubmit:true,
closeOnEscape:true,
modal:true,
jqModal: false,
savekey: [true,13],
width:550,
mtype:'POST',
url: 'MyServlet',
editData:{action:'ListInsert',myVar: function () {return myVar;}},
afterSubmit: function (response)
{
var myInfo = '<div class="ui-state-highlight ui-corner-all">'+'<span class="ui-icon ui-icon-info" '+'style="float: left; margin-right:.3em;"></span>'+ response.responseText +'</div>';
$infoTr = $("#TblGrid_" + $.jgrid.jqID(this.id) + ">tbody>tr.tinfo"),$infoTd = $infoTr.children("td.topinfo");
$infoTd.html(myInfo);
$infoTr.show();
return [true, "", ""];
},
errorTextFormat: function (response)
{
return '<span class="ui-icon ui-icon-alert" ' +'style="float:left; margin-right:.3em;"></span>' +response.responseText;
}
},
上面的代码显示了警报,但仍然显示了添加表单。myVar 包含来自其他网格的 id,如果 myVar 没有值,那么我不想显示添加表单。
提前致谢。
【问题讨论】:
-
您能提供更多代码吗?更容易告诉你的表单发生了什么
-
@Cammy 我在问题中添加了更多代码。如果您需要更多信息,请告诉我。
-
我没有意识到您正在使用框架。但是我检查了文档并没有找到任何说您可以中止在“beforeShowForm”中显示其余表单的内容。或者它可以有一个返回值 -> return[false,"Value 不能为空!"];也许重新考虑这一行
-
您可以自己关闭表单:
if(!myVar){$('#btCancel').click(); alert('...')}其中 btCancel 是表单的取消按钮。
标签: javascript jquery jqgrid