一次显示验证消息(验证摘要)而不是逐个jqgrid?

时间:2018-03-05 07:43:06

标签: javascript jquery jqgrid free-jqgrid

如果我在编辑网格行的表单中有2个字段并且它们都是必需的,那么当我单击“仅提交”时,将显示需要第一个字段的消息。当我在该字段中键入内容并提交时,将显示第二个字段验证错误。 ......等等。

有没有办法一次显示验证消息? 这是我的代码

 editrules: {                                  
                                custom_func:function (value, colName) {
                                    return validateCheck(value, colName, 'Integer', colNames[i + lenarrtype + 2]);
                                }, 
                                maxlength: colNames[i + lenarrtype + 1],
                                custom: true,
                                required: true
                            },

function validateCheck(value, column, edittype, scalesize) {

    setTimeout(function () {
        $("#info_dialog").css({
            left: "25%", // new left position of ERROR dialog
            top: "2%",   // new top position of ERROR dialog

        });
    }, 50);

    switch (edittype) {
        case ('Integer'):
            if (value < 0)
                return [false, column + " :ستون " + "مقدار غیر مجاز"];
            else if (Number(value) === value || value % 1 !== 0) {

                 return [false, column + " :ستون " + " مقدار غیر مجاز "];
            }
            else
                return [true, ""];
            break

        case ('Digit'):

            var scale_splite = value.split('.');
            if (scale_splite.length > 1) {
                if ((scale_splite[1]).length > scalesize) {
                    //return [false, column + " :ستون " + "مقدار اعشار مجاز نیست"];
                }
            }

             if (value < 0)
                return [false, column + " :ستون " + "مقدار غیر مجاز"];
             if (Number(value) === value) {
                return [false, column + " :ستون " + "مقدار غیر مجاز "];

             }
                return [true, ""];
            break
    }

}

请演示:https://jsfiddle.net/dnfk8hmr/249/

1 个答案:

答案 0 :(得分:1)

免费的jqGrid可以在内联编辑期间进行两次验证:一个是标准字段验证,您可以从旧的jqGrid获知,另一个是自定义最终验证,将在验证每个字段后进行验证。 / p>

您可以删除当前使用的所有验证规则,并添加saveRowValidation回调(例如,在jqGrid的inlineEditing参数内)。回调获得一个options参数,其中包含修改后的数据,旧数据和the answer中描述的其他一些信息。回调可以返回true以通知成功验证,也可以将errorText options属性设置为自定义错误消息并返回false。

inlineEditing: {
    key: true,
    saveRowValidation (options) {
        // options.newData, options.savedRow, options.rowid 

        if (/*some tests of options.newData*/) {
            options.errorText = "your custom error message";
            return false;
        }
        return true; // no error
    }
}
相关问题