kendo ui form update cancel button -
i trying simple kendo ui form 'save' , 'cancel' buttons. using kendo.observable bind data form. functionality trying achieve is, if 'save' button clicked, form data saved. else, if 'cancel' clicked form come read-only mode previous data present. this, first saving model data in 'originalvalue' property on click of update button. if 'cancel' clicked, 'fields' model data restored 'originalvalue'. issue , 'originalvalue' not contain original value. gets updated when user editing during 'save'. question - how retain original model data can refreshed on cancel? please find below code. appreciate help, thanks.
<script type="text/javascript"> var viewmodel = kendo.observable ({ updated: false, originalvalue: {}, update: function(e) { var original = this.get("fields"); this.set("originalvalue", original); this.set("updated", true); }, save: function(e) { e.preventdefault(); if (validator.validate()) { // make ajax call save data this.set("updated", false); } }, cancel: function(e) { var original = this.get("originalvalue"); validator.destroy(); this.set("fields", original); this.set("updated", false); }, fields: {} }); viewmodel.set("fields", formarray); kendo.bind($("#outerform"), viewmodel); // prepare validator var validator = $("#outerform").kendovalidator().data("kendovalidator");
i had make exact thing on form developing. using datasource object data had use cancelchange().
the thing did there: 1. made datasource schema:
... schema: { model: {id: "id"}} ...
2. got object editing mapped id:
clientdatasource.cancelchanges(clientdatasource.get(this.get("contactid")));
where contactid created in setdata function have passed id:
this.set("contactid", contactid);
as may have notices , understood, have problem here arent using datasource rather data fields? problem here originalvalue inside observable object , referenced variable original , has observable properties. should have variable originalvalue defined outside observable object:
var originalvalue; var viewmodel = kendo.observable ({ ...
and should send formarray variable have defaults load before observable object loaded such as:
originalvalue = formarray; viewmodel.set("fields", formarray);
so when need cancel should have:
cancel: function(e) { var original = originalvalue; validator.destroy(); this.set("fields", original); this.set("updated", false); },
i havent tested should provide guidance on how solve problem.
Comments
Post a Comment