我有一个网格用于编辑用户(权限,名称等)。
我也有一个密码字段,它在编辑模式下是只写的。
含义 - 密码不显示,但如果用户为此字段插入一个值,则密码将被更改。
我的问题是,编辑现有的用户时,我显然希望密码字段是可选的。但是当添加一个新用户时,我想让这个字段是必需的。
这是如何实现的?
谢谢jqgrid不同editrules添加和编辑时
回答
对于您的问题,您可以在编辑和添加时使用不同的验证方法。
例如:
function validate_add(posdata, obj)
{
if(posdata.PASSWORD==null || posdata.PASSWORD=="" || posdata.PASSWORD==undefined)
return [false, "Please enter the pasword"];
return [true, ""]; }
function validate_edit(posdata, obj) { //you can ignore this because you dont want to verify password }
// in jqgrid
grid.navGrid('#pager',{add:true,addtext:'Add',edit:true,edittext:'Edit',del:true,deltext:'Del', search:true,searchtext:'Find',refresh:true}, //options {width:700,reloadAfterSubmit:true, beforeSubmit:validate_edit}, // edit options {width:700,reloadAfterSubmit:true, beforeSubmit:validate_add}, // add options {}, //del options {} //search options );
桑迪普发布正确的代码,因为beforeSubmit
可用于自定义验证。
有其他方法可以做你想做的事。一个不能定义不同editrules,但可以更改beforeCheckValues方法内部的editrules
对象的值,例如或其他一些form edit eventsform edit events之前验证检查。
这里是代码的架构,可以改变editrules
:
var grid = $("#list"),
getColumnIndexByName = function(columnName) {
var cm = grid.jqGrid('getGridParam','colModel'), // grid[0].p.colModel
i=0, l=cm.length;
for (; i<l; i++) {
if (cm[i].name===columnName) {
return i; // return the index
}
}
return -1;
},
addEditrulesPassword={required:true /*some other settings can follow*/},
editEditrulesPassword={required:false /*some other settings can follow*/};
// ... first of all we define the grid
grid.jqGrid({
// all parameters including the definition of the column
// with the name 'Password' inside of `colModel`
});
grid.jqGrid(
'navGrid','#pager',{/*navGrid options*/},
{//Edit dialog options
},
{//Add dialog options
beforeCheckValues:function(postdata,$form,oper) {
// get reference to the item of colModel which correspond
// to the column 'Password' which we want to change
var cm = grid[0].p.colModel[getColumnIndexByName('Password')];
cm.editrules = addEditrulesPassword;
},
onclickSubmit:function(ge,postdata) {
// get reference to the item of colModel which correspond
// to the column 'Password' which we want to change
var cm = grid[0].p.colModel[getColumnIndexByName('Password')];
cm.editrules = editEditrulesPassword;
}
}
);
我使用方法“setColProp”这个
......
{ //Edit dialog options
beforeCheckValues: function(postdata, formid, mode) {
grid.setColProp('Password', {editrules: {required: false}});
},
{ //Add dialog options
beforeCheckValues: function(postdata, formid, mode) {
grid.setColProp('Password', {editrules: {required: true}});
}
我找到了联编辑有点脏的解决方案:
function inlineCustomValidation(value, colname) {
var savedRow = jQuery("#grid").getGridParam("savedRow");
if (savedRow[0].some_required_field == "")
//add operation validation
} else {
//edit operation validation
}
};
savedRow array。这是一个只读属性,用于内联和单元格编辑模块以存储数据,然后编辑行或单元格。请参阅单元格编辑和内联编辑。
下面的脚本来验证的jqGrid联编辑细胞,它不会允许用户以不同的点输入任何特殊字符(。)用于指定小数点
{ name: 'Amount', width: 22, label: 'Cost', editable: true, align: "right", sorttype: 'int', search: false, formatter: 'currency', formatoptions: { prefix: "$", thousandsSeparator: ",", decimalPlaces: 2, defaultValue: '0.00' },
editoptions: {
dataInit: function(element) {
$(element).keypress(function (e) {
if (e.which != 8 && e.which != 0 && e.which != 46 && (e.which < 48 || e.which > 57)) {
return false;
}
});
}
}
},
- 1. 如何在jqGrid中添加和编辑表单的不同编辑选项
- 2. jqGrid从navGrid添加/编辑不工作
- 3. jqGrid - 动态更改列模型上的可编辑属性时出现editrules
- 4. 添加和编辑的不同字段
- 5. JQGrid为添加,编辑,删除设置不同的URL
- 6. jqGrid的添加和编辑表单属性不工作
- 7. Jqgrid添加和编辑url不能按预期工作
- 8. 上传文件添加/编辑jqgrid?
- 9. Jqgrid无法添加或编辑数据
- 10. jqgrid编辑并添加“tab”键的行
- 11. jqgrid - 编辑新添加的行
- 12. 将编辑链接添加到JQGrid
- 13. 的jqGrid - 添加/编辑对话框
- 14. JQGRID(开源)示例代码MYSQL和编辑和添加行
- 15. jqGrid宽度/高度jqGrid添加/编辑面板
- 16. jqGrid - 在导航器上添加,删除和编辑行
- 17. jqgrid,帮助添加,编辑和删除行
- 18. 如何添加编辑和删除图标在jQGrid操作列
- 19. JQGRID - 我正在使用添加新记录和编辑表格
- 20. jqGrid内联编辑添加新行后不工作
- 21. 的jqGrid - 添加,编辑,删除不工作
- 22. jqGrid - 添加,编辑,搜索按钮不起作用
- 23. jqgrid编辑,保存和esc
- 24. jEditable编辑和添加行
- 25. jqgrid - 如何在编辑或添加记录时将jquery ui选项卡添加到jqgrid对话框中?
- 26. 编辑模式下的Uitableview:如何同时添加“+”(添加)和“ - ”(删除)按钮?
- 27. Jqgrid使用editrules时关注当前单元格
- 28. 禁用编辑(添加,编辑和删除)的jqGrid,而不是隐藏(默认行为)
- 29. 添加/编辑
- 30. 在jqgrid添加/编辑表单中显示列的两个编辑字段
你是对的,'beforeSubmit'可以用于自定义验证。所以,从我+1。在你的答案被接受后,我会发布另一种方式的描述:如何使用*标准验证*与'editrules',但是**添加和编辑对话框有两个不同的**'editrules'值。 – Oleg 2011-05-23 10:24:20
恐怕你不能这样做
editrules
,因为editrules是common_rules
模块,这是常见的添加和编辑...它会很好,如果你可以做到这一点... – Sandeep 2011-05-23 10:51:29@Sandeep:有没有办法**定义**不同的'editrules',但是可以**改变'beforeCheckValues'方法内'editrules'对象的值,或者其他[form编辑事件](http://www.trirand .com/jqgridwiki/doku.php?id = wiki:form_editing#events)在验证检查之前调用。 – Oleg 2011-05-23 10:57:14