0

我需要允许值 's1pdtCalc' 为空并允许保存记录。现在我收到错误消息“s1pdtCalc 为空或不是对象”。感谢您的帮助,这是代码。

 function validateForm(values) {
        var pass = true;
        // check percent days turnaround

        var ck = values.s1pdtCalc.toString ();
        if (ck > "") {
            var t1 = values.s1pdtNTTd.toString (); //NEMIS Turn around
            var t2 = values.s1pdtTAd.toString (); //NEMIS Turn adjustment
            var t3 = values.actDays.toString ();  //NEMIS Turn adjustment
            t1 = (t1!=null?t1.trim ():0);

            if (ck == "MINUS") {
                if ((t1-t2) > t3) {
                    errorMsgs += '<br /> s1pdtATT - Percent days turnaround < 4.0.0. exceeds the number of activation days';
                }
            }
            else {
                if ((t1+t2) > t3) {
                    errorMsgs += '<br /> s1pdtATT - Percent days turnaround < 4.0.0. exceeds the number of activation days';
                }
            }
        }

        if (errorMsgs > "") {
            pass = false
        }
        return pass;
    }
4

1 回答 1

1

您不能在不存在的对象上调用方法。s1pdtCalc如果在尝试调用方法之前不存在,您需要将其默认为:

function validateForm(values) {
    ...
    // set ck to an empty string if values.s1pdtCalc doesn't exist
    var ck = values.s1pdtCalc ? values.s1pdtCalc.toString() : '';
    ...
于 2012-09-13T14:33:26.307 回答