2013-12-12 56 views
1

之情況:我已經添加了驗證,以觀察到的陣列,例如是關於一個可觀察的領域中觀察到的陣列 如:沒有得到errorElementClass

this.field = ko.observable().extend({ 
      required: { params: true, message: "field is required." }, 
      digit: { params: true, message: "field must be number." }, 
      min: { params: 0, message: "field must be between 0 to 9999." }, 
      max: { params: 9999, message: "field must be between 0 to 9999." } 
     }); 

而且初始化驗證:

ko.validation.init({ 
      registerExtenders: true, 
      messagesOnModified: false, 
      insertMessages: false, 
      decorateElement: true, 
      errorElementClass: 'input-validation-error', 
      errorMessageClass: 'field-validation-error' 
     }); 

但不獲得errorElementClass: 'input-validation-error',用於除需要驗證之外的其他驗證注意:對於其他驗證規則違規,它取class = valid,但會顯示錯誤消息'

回答

0

我已經安裝類似的事情在jsFiddle

ko.validation.init({ 
    registerExtenders: true, 
    messagesOnModified: false, 
    insertMessages: true, 
    decorateElement: true, 
    errorElementClass: 'input-validation-error', 
    errorMessageClass: 'field-validation-error' 
}); 

function Money() { 
    this.Amount = ko.observable().extend({ 
     required: { 
      params: true, 
      message: "field is required." 
     }, 
     digit: { 
      params: true, 
      message: "field must be number." 
     }, 
     min: { 
      params: 0, 
      message: "field must be between 0 to 9999." 
     }, 
     max: { 
      params: 9999, 
      message: "field must be between 0 to 9999." 
     } 
    }); 

    this.onSubmit = function (e) { 
     return this.Amount.isValid(); 
    } 
} 

ko.applyBindings(new Money()); 

試試這個在FF 我建議檢查以下步驟

  1. 參考腳本文件按照以下順序

    • jQuery的
    • 淘汰賽
    • 淘汰賽驗證
  2. 確保在最高層在domready中ko.validations.init調用

  3. 版本錯誤匹配是不存在的。最新ko.validation似乎與淘汰賽3.0