0

I need to allow for the value 's1pdtCalc' to be null and allow for the record to be saved. Right now I get the error message "s1pdtCalc is null or not an object". Thanks for the help and here is the code.

 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;
    }
michael
  • 91
  • 1
  • 2
  • 12

1 Answers1

1

You can't invoke methods on objects that don't exist. You'd need to default the s1pdtCalc to something if it doesn't exist before attempting to invoke methods:

function validateForm(values) {
    ...
    // set ck to an empty string if values.s1pdtCalc doesn't exist
    var ck = values.s1pdtCalc ? values.s1pdtCalc.toString() : '';
    ...
jbabey
  • 45,965
  • 12
  • 71
  • 94