2012-03-15 2 views
2

필드에 "31/12/2012"를 입력하면 (날짜 형식은 MM/DD/YYYY) 필드에서 "2014 년 7 월 12 일"으로 변경됩니다. 오히려 "유효하지 않은"오류 메시지로 인해 오류가 발생합니다.ExtJS 구문 분석 날짜가 잘못

나는 이전 개발자에서이 코드를 상속 :

function dateRangeCheck(val, field) { 
    field.vtypeText = ''; 

    var date = field.parseDate(val); 
    if (!date) { 
     field.vtypeText = val + ' is not a valid date - it must be in the format (MM/DD/YYYY).'; 
     return false; 
    } 

    var retVal = true; 

    if (field.fromField) { 
     var fromField = Ext.getCmp(field.fromField); 
     var fromDate = fromField.parseDate(fromField.getValue()); 
     // If we don't have a fromDate to validate with then return true 
     if (!fromDate) 
      return true; 

     retVal = (date >= fromDate); 

     if (retVal) 
      fromField.clearInvalid(); 
    } 
    else if (field.toField) { 
     var toField = Ext.getCmp(field.toField); 
     var toDate = toField.parseDate(toField.getValue()); 
     // If we don't have a toDate to validate with then return true 
     if (!toDate) 
      return true; 

     retVal = (date <= toDate); 

     if (retVal) 
      toField.clearInvalid(); 
    } 

    if (!retVal) { 
     field.vtypeText = 'From Date must be less than or equal to To Date.'; 
    } 
    return retVal; 
} 

내가이가 "3"현장에서, 그것은 JS를 던졌습니다 입력하는 즉시 기본 'DATERANGE'VTYPE를 사용하려고 런타임 예외 '객체가이 속성 또는 메소드를 지원하지 않습니다'.

+0

ExtJS4를 사용하고 있습니까? Ext.form.field.Date 구성 요소를 사용 하시겠습니까? –

+0

잘 모르겠습니다. ExtJS 버전에서 찾을 수있는 유일한 참조는 3.0 RC 1.1입니다. – michaelkoss

+0

'Ext.version ||을 입력하여 버전을 얻을 수 있습니다. Ext.load()를 사용하여 콘솔에 Ext.getVersion(). version'을로드했습니다. –

답변

1

parseDate으로 전화하면 strict switch 세트 만 있으면됩니다. (즉 방지 자바 스크립트 날짜 "롤오버") (기본값 false로) 구문 분석하는 동안 날짜 문자열의 유효성을 검사 (선택 사항) 진정한

strict. 잘못된 날짜 문자열은 구문 분석시 null을 반환합니다.

> Date.parseDate('31/12/2012','m/d/Y') 
    Sat Jul 12 2014 00:00:00 GMT-0500 (Central Daylight Time) 
> Date.parseDate('31/12/2012','m/d/Y', true) 
    null 
하여 DateField의 parseDate 방법은 개인 및 문서화되지 않은 것입니다

하고 discussion는 ExtJS로 3.x의 엄격한 날짜 구문 분석이 결코 어떤 열매를 지루하게하지 허용합니다. 가장 좋은 방법은 재정의를 사용하여 엄격한 날짜 구문 분석을 허용하는 것입니다. 당신은 세계적으로 Date.useStrict = true을 설정할 수 있으며하여 DateField 기본적으로 그것을 사용

// before you use your DateFields 
Ext.override(Ext.form.DateField, { 
    safeParse : function(value, format) { 
     if (Date.formatContainsHourInfo(format)) { 
      // if parse format contains hour information, no DST adjustment is necessary 
      return Date.parseDate(value, format, this.strict); 
     } else { 
      // set time to 12 noon, then clear the time 
      var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, this.strict); 

      if (parsedDate) { 
       return parsedDate.clearTime(); 
      } 
     } 
    } 
}); 

//... and in your DateField config: 
strict: true, 
+0

ext-all-debug.js에 parseDate의 정의가 있습니다. 파일의 헤더는 "Ext JS Library 3.0 RC 1.1"이라고 말합니다. 정의는 6051 행에 있습니다. 자바 스크립트에는별로 좋지 않으며 다른 함수 및 속성에 대한 많은 참조가 있습니다. 나는 그것을 추적하려고 노력하고있다. – michaelkoss

+0

방금'Ext.form.DateField' 코드를 살펴 보았습니다. * parseDate 메소드가 있습니다. 단지 private이고 문서화되어 있지 않습니다. 나는 당신이 오버라이드로 이것을 처리 할 필요가 있다고 생각한다. 나는 곧 내 대답을 업데이트 할 것이다. – wes

2

참고.

enter image description here

내선 들어 4+ 대신 Ext.Date.useStrict = true이 될 것입니다.

관련 문제