Jqgrid - 选择下拉列表的验证
Jqgrid - Validation on selecting dropdown
我有这个带有下拉列表的列,目前当我 select 下拉列表中的任何值都会被保存,我想在保存之前 select 从下拉列表中输入一个值时添加验证,例如,
{name:'color_name',
cellattr: function (rowid, cellValue) {
if ($.inArray(cellValue, hilightcolorcell) < 0) {
return " class='redcells'";
}
},editable:true,edittype:"select",editoptions:
{value:"PURPLE:PURPLE;PINK:PINK;GREEN:GREEN"}}
如果 selected 值是粉红色,我想要一个带有保存和取消按钮的验证提示,类似这样,选定的值是:粉红色,保存取消
这是演示 link https://jsfiddle.net/kwu7v3fc/3/
请帮忙。
有很多方法可以实现您的要求。在我看来,最本机的做法是在 select 选项的更改和 before 真正保存它时直接询问用户的确认。可以添加 "change" 事件处理程序,它可以满足您的所有需求。相应的实现如下例所示
editoptions: {
value: "PURPLE:PURPLE;PINK:PINK;GREEN:GREEN",
dataEvents: [
{
type: "change",
fn: function (e) {
if ($(this).val() === "PINK") {
if (!confirm("Are you sure you want PINK?")) {
// reset the value to the previous one
var savedRow = $("#rowed5").jqGrid("getGridParam", "savedRow");
$(this).val(savedRow[0].v);
}
}
}
}
]
}
我有这个带有下拉列表的列,目前当我 select 下拉列表中的任何值都会被保存,我想在保存之前 select 从下拉列表中输入一个值时添加验证,例如,
{name:'color_name',
cellattr: function (rowid, cellValue) {
if ($.inArray(cellValue, hilightcolorcell) < 0) {
return " class='redcells'";
}
},editable:true,edittype:"select",editoptions:
{value:"PURPLE:PURPLE;PINK:PINK;GREEN:GREEN"}}
如果 selected 值是粉红色,我想要一个带有保存和取消按钮的验证提示,类似这样,选定的值是:粉红色,保存取消
这是演示 link https://jsfiddle.net/kwu7v3fc/3/
请帮忙。
有很多方法可以实现您的要求。在我看来,最本机的做法是在 select 选项的更改和 before 真正保存它时直接询问用户的确认。可以添加 "change" 事件处理程序,它可以满足您的所有需求。相应的实现如下例所示
editoptions: {
value: "PURPLE:PURPLE;PINK:PINK;GREEN:GREEN",
dataEvents: [
{
type: "change",
fn: function (e) {
if ($(this).val() === "PINK") {
if (!confirm("Are you sure you want PINK?")) {
// reset the value to the previous one
var savedRow = $("#rowed5").jqGrid("getGridParam", "savedRow");
$(this).val(savedRow[0].v);
}
}
}
}
]
}