Reputation: 3231
For knockout required validation, the onlyIf is used in this way. How about maxLength validation? I have tried as follow but not working. Hope someone could help on this.
self.postalCode.extend({
required: {
message: "Postal Code is required",
onlyIf: function() {
return self.noPostalCode() === false;
}
}
});
// Not Working
self.postalCode.extend({
maxLength: 3 {
message: "Postal Code is required",
onlyIf: function() {
return self.noPostalCode() === false;
}
}
});
Upvotes: 3
Views: 5818
Reputation: 6045
All you need to do is set maxLength
property value using params
viewModel:
self.postalCode.extend({
maxLength: {
message: "Postal Code is required",
onlyIf: function () {
return self.noPostalCode() === false;
},
params: 3
}
});
working sample here
Upvotes: 7