Vote count:
0
I'm using knockout mapping to bind a model from the server and then i'm adding validation to it. So far so good.
I have a list of products that have constraints on the collection and the individual product data. Since I don't generate the class in javascript for the observableArray, i'm having difficulty understanding how I can extend it so I can add validation to the product class within the observable array.
I get the feeling that this may not be possible if I don't create and extend the object in javascript.
$.getJSON("api/Companies/Products", function (model) {
var serverModel = ko.mapping.fromJS(model);
// Normal object - Fine
serverModel.someObject.Extend({ required: { params: true, message: 'Required' });
// products is an observable array of 'product'
serverModel.products.Extend({
validation: [ {
validator: function (val, count) {
return val.length > count;
},
message: 'At least one product must be entered',
params: 0
}]
});
// How do I extend product??
serverModel.products.product.extend({ ...? });
I don't really want to loop through and check them individually as I want the error message next to the item and for performance reasons.
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire