Tag Archives: JavaScript

Override X-editable Value After Save

I wasn’t able to find a way to set an X-editable field to a specific value after a submit. After poking around in the source for X-editable I noticed the following:

//if success callback returns object like {newValue: <something>} --> use that value instead of submitted
//it is useful if you want to change value in url-function
if(res && typeof res === 'object' && res.hasOwnProperty('newValue')) {
  newValue = res.newValue;

Once I found this, setting the field to the proper value was very straightforward:

  success: function editable_success(response){
    var json_response = JSON.parse(response);
    if(json_response.success) {
      if(json_response.new_value) {
        return {newValue: json_response.new_value};