jquery - Knockout clearing field in view model after submission -


how can clear value of department name in view model after submit department server saved? here code:

self.adddepartmentmodel.adddepartment = function () {     self.errors = ko.validation.group(this, { deep: true, observable: false });     if (self.adddepartmentmodel.errors().length == 0) {         $.ajax({             url: "/department/add/",             type: 'post',             data: ko.tojson(self.adddepartmentmodel),             contenttype: 'application/json',             success: function (result) {                 $('#success').html('department added successfully.');                 $("#success").dialog({                     dialogclass: 'noclose',                     autoopen: true,                     show: "blind",                     hide: "explode",                     modal: true,                     open: function(event, ui) {                         settimeout(function() {                             $('#success').dialog('close');                         }, 3000);                     }                 });                 self.listofdepartments.getlistofalldepartments();                 $("#departmentnametextbox").val("");                 self.adddepartmentmodel.departmentname = null;             }         });     } else {         self.adddepartmentmodel.errors.showallmessages();         return;     } }; 

i want field cleared after submit button pressed. if make field value empty string , hit submit again submits value in text box after cleared it. suggestions how clear value of departmentname?

thanks

i assume self.adddepartmentmodel.departmentname observable property, since bound textbox , user entered value. if that's case, try

self.adddepartmentmodel.departmentname(null); 

instead of

$("#departmentnametextbox").val(""); self.adddepartmentmodel.departmentname = null; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -