jqGrid密码确认
我试图在jqGrid表单中创建密码确认输入,但我相信我做得不对。原因是在我的实现中,当您编辑已定义的用户时,两个字段(password和password\u confirm)都包含带星号的用户密码 这并没有什么错,但我认为最好在编辑时让两个字段都为空,并且只在它们包含值时验证它们。这是代码的一部分: colNames:[“名称”、“用户名”、“电子邮件”、“密码”、“确认密码”] colModel:[{name:“name”,index:“name”,可编辑:true,可编辑规则:{required:true} 其他领域 {name:“password”,index:“password”,edit:true,edittype:“password”,hidden:true,editrules:{edithidden:true,required:true}, {name:“confirm_password”,index:“confirm_password”,edit:true,edittype:“password”,hidden:true,editrules:{edithidden:true,required:true} 正如您所见,我已经定义了两个对象,一个用于实际密码,另一个用于确认。当我填充网格时,我为两个字段返回相同的值 对于更好的实施有什么想法吗jqGrid密码确认,jqgrid,Jqgrid,我试图在jqGrid表单中创建密码确认输入,但我相信我做得不对。原因是在我的实现中,当您编辑已定义的用户时,两个字段(password和password\u confirm)都包含带星号的用户密码 这并没有什么错,但我认为最好在编辑时让两个字段都为空,并且只在它们包含值时验证它们。这是代码的一部分: colNames:[“名称”、“用户名”、“电子邮件”、“密码”、“确认密码”] colModel:[{name:“name”,index:“name”,可编辑:true,可编辑规则:{requir
非常感谢。我已经搜索了一段时间了,我想出了自己的解决方案。我不想在DB中添加一个字段-在我的例子中是Redis-所以我需要动态创建一个用于密码检查的字段,并验证它是否匹配第一个密码字段。密码检查字段将提交到后面最后,这不是一个bug,而是一个特性 继续写代码 我们定义的第一个函数是创建密码检查字段并将其附加到原始密码字段的函数:
function createPassCheck(el) {
// Create the containing table row
var passCheck = $("<tr></tr>").addClass("FormData")
.attr({
id: "tr_passwordCheck",
rowpos: 20
});
// Create a cell for the label and add it to the row
var passCheckLabelTd = $("<td></td>")
.addClass("CaptionTD").text("Password Check");
passCheck.append(passCheckLabelTd);
// Prepare the cell for the input box. All
// the cells have a non breaking space, we add
// one as well to keep aligned. We then add it to the row.
var passCheckTd = $("<td> </td>")
.addClass("DataTD");
passCheck.append(passCheckTd);
// Create an input box, and add it to the input cell
var passCheckInput = $("<input></input>")
.addClass("FormElement ui-widget-content ui-corner-all")
.attr({
id: "passwordCheck",
name: "passwordCheck",
role: "textbox",
type: "password"
});
passCheckTd.append(passCheckInput);
// Finally append the row to the table, we have been called after
// the creation of the password row, it will be appended after it.
var tbodyEl = el.parentNode.parentNode.parentNode;
tbodyEl.appendChild(passCheck[0]);
}
最后,我们将使用一个函数在编辑时将密码设置为空,我们将通过注册为自定义格式化程序来实现这一点
function customPassFormat(cellvalue, options, rowObject) {
// When asked to format a password for display, simply
// show a blank. It will make it a bit easier when
// we editing an object without changing the password.
return "";
}
现在,我们可以在jqGrid中定义密码字段并使其特殊化:
jQuery("#crud").jqGrid({
....
....
colModel:[
....
{
name:'password',
index:'password',
width:80,
align:"right",
editable:true,
// It is hidden from the table view...
hidden: true,
editrules:{
// ...but we can edit it from the panel
edithidden: true,
// We are using a custom verification
custom:true,
// This is the function we have created
// to verify the passwords
custom_func: customPassCheck
},
edittype: 'password',
// Our custom formatter that will blank the
// password when editing it
formatter: customPassFormat,
editoptions: {
// This is where the magic happens: it will add
// the password check input on the fly when editing
// from the editing panel.
dataInit: createPassCheck
}
},
....
....
这就是所有的人
Fabio已经搜索了一段时间,我想出了自己的解决方案。我不想在DB中添加一个字段-在我的例子中是Redis-因此我需要动态创建一个用于密码检查的字段,并验证它是否与第一个密码字段匹配。密码检查字段将提交到后端,即s不是一个bug,而是一个特性 继续写代码 我们定义的第一个函数是创建密码检查字段并将其附加到原始密码字段的函数:
function createPassCheck(el) {
// Create the containing table row
var passCheck = $("<tr></tr>").addClass("FormData")
.attr({
id: "tr_passwordCheck",
rowpos: 20
});
// Create a cell for the label and add it to the row
var passCheckLabelTd = $("<td></td>")
.addClass("CaptionTD").text("Password Check");
passCheck.append(passCheckLabelTd);
// Prepare the cell for the input box. All
// the cells have a non breaking space, we add
// one as well to keep aligned. We then add it to the row.
var passCheckTd = $("<td> </td>")
.addClass("DataTD");
passCheck.append(passCheckTd);
// Create an input box, and add it to the input cell
var passCheckInput = $("<input></input>")
.addClass("FormElement ui-widget-content ui-corner-all")
.attr({
id: "passwordCheck",
name: "passwordCheck",
role: "textbox",
type: "password"
});
passCheckTd.append(passCheckInput);
// Finally append the row to the table, we have been called after
// the creation of the password row, it will be appended after it.
var tbodyEl = el.parentNode.parentNode.parentNode;
tbodyEl.appendChild(passCheck[0]);
}
最后,我们将使用一个函数在编辑时将密码设置为空,我们将通过注册为自定义格式化程序来实现这一点
function customPassFormat(cellvalue, options, rowObject) {
// When asked to format a password for display, simply
// show a blank. It will make it a bit easier when
// we editing an object without changing the password.
return "";
}
现在,我们可以在jqGrid中定义密码字段并使其特殊化:
jQuery("#crud").jqGrid({
....
....
colModel:[
....
{
name:'password',
index:'password',
width:80,
align:"right",
editable:true,
// It is hidden from the table view...
hidden: true,
editrules:{
// ...but we can edit it from the panel
edithidden: true,
// We are using a custom verification
custom:true,
// This is the function we have created
// to verify the passwords
custom_func: customPassCheck
},
edittype: 'password',
// Our custom formatter that will blank the
// password when editing it
formatter: customPassFormat,
editoptions: {
// This is where the magic happens: it will add
// the password check input on the fly when editing
// from the editing panel.
dataInit: createPassCheck
}
},
....
....
这就是所有的人
法比奥