2012-09-13 3 views
0

's1pdtCalc'값을 null로 허용하고 레코드를 저장할 수 있도록 허용해야합니다. 지금 "s1pdtCalc가 null이거나 개체가 아닙니다"라는 오류 메시지가 나타납니다. 도움을 주셔서 감사합니다. 여기 코드가 있습니다.Ext JS 자바 스크립트 Null 값 유효성 검사

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

답변

1

존재하지 않는 개체에 대해서는 메서드를 호출 할 수 없습니다. 메서드 호출을 시도하기 전에 존재하지 않는 경우 s1pdtCalc을 기본값으로 설정해야합니다.

function validateForm(values) { 
    ... 
    // set ck to an empty string if values.s1pdtCalc doesn't exist 
    var ck = values.s1pdtCalc ? values.s1pdtCalc.toString() : ''; 
    ... 
+0

감사합니다. – michael

관련 문제