Skip to content Skip to sidebar Skip to footer

Knockoutvalidation And The Conditional Required Rule

I am trying to use KnockoutValidation with conditional statements. See code below: self.transactionType = ko.observable('Option1'); self.ConditionalField = ko.observable().extend(

Solution 1:

I have solved it.

First of all I made the mistake of declaring the transactiontype after I had defined the conditionalfield. The end code that works looks like this:

self.transactionType = ko.observable("Option1");

self.conditionalField = ko.observable().extend({
  required: {
    onlyIf: function() { 
      returnself.transactionType () == "Option2";
    }
  }
});

Post a Comment for "Knockoutvalidation And The Conditional Required Rule"