I have a model which contains a multi select and a text box.
I want a validation to show up if none of them are populated, but no validation error if at least one of them is populated. (either one item in the select clicked, or some text).
I have a working plunkr here: plnkr.co/edit/pwKohFTmLPW1BKNwHxWR?p=preview
I tried thousands of things with no success.
The problem at its core is that self.isValid() does not trigger the validation function SubscribersOrEmails
Currently I have this:
var ReportSchedule = function () {
self.Subscribers = ko.observableArray().extend({ required: { onlyIf: function () { return self.SubscribersOrEmails === 0; } } });
self.Emails = ko.observableArray().extend({ required: { onlyIf: function () { return self.SubscribersOrEmails === 0; } } });
self.EmailText = ko.observable();
self.SubscribersOrEmails = ko.computed(function () {
var counter = 0;
if (self.Emails != null && self.Subscribers != null) {
counter = self.Emails().length + self.Subscribers().length;
}
console.log("counter: " + counter);
return counter;
});
}
I tried custom validators and every combination under the sun.
Any ideas what to try next?
I am using knockout v3.2.0-beta