1

I have items dispersed within my view that are visible based on dates, drop down selections and the like. I would like to use ko validation because its nice to put validation logic in my model and not have to use a stupid form like you would with jquery validation.

The bonus I am seeing with jquery validation is that it only validates visible items even if they have the required class. Is there anyway to get this functionality from ko validation?

4

1 回答 1

1

在您的淘汰赛模型中,我想您应该有一个可见性标志。您可以使用onlyIf基于标志的选项。就像是:

self.IsFieldVisible = ko.observable(true); //Or False
self.FieldToValidate= ko.observable().extend({
  required: {
    onlyIf: function () { 
      return self.IsFieldVisible();
    }
  }
});
于 2013-05-06T01:32:20.640 回答