You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you will have a viewmodel property that is only required in depending on some other circumstances. You can use the onlyIf parameter, which accepts a function, to specify when that field is required. The required validator will only be applied if the onlyIf function returns true.
For example, consider an address block that requires a postal code unless a "noPostalCode" field is set to true.
self.postalCode.extend({
required: {
message: "Postal Code is required",
onlyIf: function () { return (self.noPostalCode() === false); }
}
});