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};

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s