如何为添加和添加不同的编辑选项在jqGrid中编辑表单 [英] How to have different edit options for add & edit forms in jqGrid
问题描述
我有一个jqGrid,上面写着要以表格形式编辑的用户信息.用户名是不可变的,但应以表格形式显示,以便用户知道他们正在编辑的用户.密码仅可编辑.所以在我的colModel中,我有这样的设置:
I have a jqGrid with say user information which is to be edited in a form. The username is immutable but should appear in the form so the user is aware which user they are editing. The password is edit only. So in my colModel I have settings like this:
{name:'username', index:'username', width:155, editable:true, editoptions: {readonly:'readonly'}},
{name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}},
此功能可以很好地进行编辑.我的问题是添加我需要使用户名非只读".我看不到用于控制添加表单和编辑表单的属性.也许我可以使用afterShowForm
事件来更改editoptions?有人做过这样的事吗?
This works fine for edit. My problem is on add I need to make the username 'not readonly'. I don't see properties to control the add form vs the edit form. Perhaps I can use the afterShowForm
event to change the editoptions? Has anybody done anything like this?
推荐答案
万一它对其他人有用,我将无法完全做到这一点,但找到了一种实现最终结果的方法.
In case it is useful to anybody else, I wasn't able to do this exactly but found a way to accomplish the end result.
因此,我没有使用editoptions将表单字段设置为只读,而是使用add&的beforeShowForm事件.编辑选项以添加和/或删除只读属性.
So instead of using editoptions to set the form field to readonly I used the beforeShowForm event of the add & edit options to add and or remove the readonly attribute.
因此没有只读的colmodel:
So the colmodel without the readonly:
{name:'username', index:'username', width:155, editable:true},
{name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}},
和navGrid编辑&添加选项以打开只读(添加)或关闭(编辑).注意,INPUT标签的ID将是colModel中name
字段的值:
and the navGrid edit & add options to turn the readonly on (for add) or off (for edit). Note, the INPUT tag's ID will be the value of the name
field in the colModel:
jQuery("#user-grid").jqGrid('navGrid','#user-grid-pager',
{ }, //options
{ // edit options
beforeShowForm: function(frm) {
$('#username').attr('readonly','readonly');
}
},
{ // add options
beforeShowForm: function(frm) {
$('#username').removeAttr('readonly');
}
},
{ }, // del options
{ } // search options
);
另一方面,虽然我知道(根据jquery dump),'frm'函数arg是一个包含表单的jQuery对象,但我无法获得选择器来成功选择想要的孩子,所以我只使用了id匹配colModel名称.
On a side note, while I know (according to jquery dump) the 'frm' function arg is a jQuery object containing the form, I could not get a selector to successfully select the child I wanted so I just used the id which matches the colModel name.
这篇关于如何为添加和添加不同的编辑选项在jqGrid中编辑表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!