I'm beginning to play with Knockout.JS and I'm trying to compute a sum of 'points' across valid fields in my viewmodel, but have no idea how to go about this. The idea is that as the form is filled I can display a smart progress bar based on the completed value of points each validated field contains.
How would I setup dynamicpoints to always contain a live sum of the fields?
Brief snippet of the view model:
myViewModel = ko.validatedObservable({
fields: {
firstname: {
label: "First Name",
value: ko.observable("").extend({
required: true
}),
points: 100
},
lastname: {
label: "LastName",
value: ko.observable("").extend({
required: true,
minLength: 2
}),
points: 200
}
}
dynamicpoints: ko.computed { ??? }
})