I am trying to understand How X-editable stores the values.
For example I have the following code:
HTML:
<a class="editable" data-type="select" data-value="1">value-1</a>
JavaScript:
$.fn.editable.defaults.mode = 'inline'; $('.editable').html('value-2'); $('.editable').data('value',2); $('.editable').editable({ source: function () { return [ { value: 1, text: "value-1" }, { value: 2, text: "value-2" }, { value: 3, text: "value-3" } ]; } });
And here is the jsfiddle to play with
As you can see it works just fine. At the first step I declare the value of dropdown equal to "value-1" and then I change it to "value-2" in JavaScript. As the result you can "value-2" on the page and "value-2" after clicking to dropdown the same value will be chosen.
At this step I will modify JavaScript a bit as below:
//$('.editable').html('value-2'); $('.editable').data('value',2);
Again the results are quite expectable. You will see "value-1" on the page, but "value-2" will be selected when opening dropdown.
Now lets change the JavaScript code in the opposite way
$('.editable').html('value-2'); //$('.editable').data('value',2);
After such modifications the value on the page will be equal to "value-2", but selected value in dropdown when starting to edit will be "value-1". So also quite logical behavior.
Question:
What is not expected for me is that saving the changes by clicking 'ok' button of editable control does not change data-value
attribute, it only change the displayed text. For example, if we update the value to "value-3"
and click on 'OK' the data-value
attribute will be still equal to 1. So how does the plugin choose the proper value inside the dropdown after opening it again?
UPD:
The most proper way to change the value of editable from the code is to use
$('.editable').editable('setValue', 'value-1');