Jqgrid-选择下拉列表时的验证 [英] Jqgrid - Validation on selecting dropdown

查看:76
本文介绍了Jqgrid-选择下拉列表时的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此列中有下拉菜单,例如,当我从下拉菜单中选择任何值时,它将被保存,例如,我想在保存之前从下拉菜单中选择一个值时添加一个验证

{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"}}

如果选择的值是PINK,我想使用保存并取消"按钮来显示验证提示,则选择的值是:PINK,SAVE CANCEL

这是演示链接 https://jsfiddle.net/kwu7v3fc/3/

请帮助.

解决方案

有很多方法可以实现您的需求.在我看来,最原生的方法是直接询问用户有关选择选项更改的确认,然后之前真正保存它.您可以添加更改"事件处理程序,该程序可以完成您需要的所有操作.相应的实现将类似于下面的示例

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);
                    }
                }
            }
        }
    ]
}

请参阅修改后的演示 https://jsfiddle.net/OlegKi/kwu7v3fc/5/

i have this column with dropdown, currently when i select any value from the dropdown it it gets saved, i would like to add a validation while selecting a value from dropdown before saving, for example,

{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"}}

if the selected value was PINK, i wanted to have a validation prompt with Save and Cancel button something like this, Selected Value is : PINK, SAVE CANCEL

this is demo link https://jsfiddle.net/kwu7v3fc/3/

please help.

解决方案

There are many ways to implement your requirement. The most native would seems to me to ask the confirmation from the user directly on change of the select option and before real saving it. One can add "change" event handler, which do all you need. The corresponding implementation will look like on the example below

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);
                    }
                }
            }
        }
    ]
}

See the modified demo https://jsfiddle.net/OlegKi/kwu7v3fc/5/

这篇关于Jqgrid-选择下拉列表时的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆