admin管理员组

文章数量:1302379

in my x-editable field I have a textarea that I want to update based on the returned value. This works when I use $(this).html(newVal); as shown below

success: function(response, newValue) {
  newVal=unescape(JSON.parse(response).VALUE)
  $(this).html(newVal);
}  

the problem is when I click to edit the field the second time, the value inside the input object (class: editable-input) stays the same as it was when it was sent. Is there a way to fix this?

in my x-editable field I have a textarea that I want to update based on the returned value. This works when I use $(this).html(newVal); as shown below

success: function(response, newValue) {
  newVal=unescape(JSON.parse(response).VALUE)
  $(this).html(newVal);
}  

the problem is when I click to edit the field the second time, the value inside the input object (class: editable-input) stays the same as it was when it was sent. Is there a way to fix this?

Share Improve this question asked Dec 4, 2013 at 3:48 DanielDaniel 35.7k17 gold badges114 silver badges161 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

the simplest way:

        $('.textarea').editable({
            success: function(response, newValue) {
                    return {newValue: response.newValue};
                }
            }
        });

remember to return newValue variable in response content:

{"newValue":"some_string_new_value"}

this worked. I'm setting the value by calling this function in the on success callback

  function formatXEditable($item, $val){
    $val = $val.replace(/<br\s*\/?>/mg,"\n");
    $($item).on('shown', function(e, editable) {
      editable.input.$input.val($val);
    });
  }

本文标签: javascriptupdating xeditable input field based on returned valueStack Overflow