I am using knockout for data binding on a form contained on a modal. Once the user submits the form, the modal closes on a successful post. I would also like to clear all the observable values from my knockout view model so the user can open the modal and submit a new form from scratch. I do not want to lose the ko.observable bindings that are already set on the fields.
For context, my viewmodel is a child of another view model.
In my parent view model
self.childElement = ko.observable(new childElementVm());
my child view model
var childElementVm = function (){
var self= this;
self.property1 = ko.observable()
self.property2 = ko.observable()
self.property3 = ko.observable()
self.property4 = ko.observable()
self.property5 = ko.observable()
self.property6 = ko.observable()
self.array1 = ko.observableArray()
self.array2 = ko.observableArray()
self.array3 = ko.observableArray()
self.array4 = ko.observableArray()
//several more observables
//a smattering of functions including some self.property.subscribe functions
$.ajax({
//post
}).done(function(){
$('#myModal').modal('hide');
//reset all values in childElementVm
});
}
childElementVm
? Can you show its source? – Steve Danner