Nestable2
Nestable2 copied to clipboard
Serialize get data-* from DOM, bypass data-* cache
The jQuery .data() function caching the data-attributes. If we need to dynamically edit the data attribute, the value isn't updated in the output.
Expected behavior
In this example the problem is fixed https://jsfiddle.net/4df99Lts/3/ (Nestable2 1.6.0-fixed)
Actual behavior
In this example the problem https://jsfiddle.net/4df99Lts/1/ (Nestable2 1.6.0)
Steps to reproduce the behavior
Touch "Configure" on ID: 5. Change value and save. In version https://jsfiddle.net/4df99Lts/3/ the problem is fixed, also, in the https://jsfiddle.net/4df99Lts/1/ no.
Best regards
@arturu I'm willing to merge this PR, but I have one issue: backward compatibility. Before your changes:
[{"id":1,"value":"test"}]
After your changes (Integer to string convertion):
[{"id":"1","value":"test"}]
Your issue can be fixed without this PR, you need change this line:
$("#list-dd3 li[data-id=" + id + "]").attr('data-'+formInput[i],a);
with
$("#list-dd3 li[data-id=" + id + "]").data(formInput[i],a);
and probably in this line:
$("#list-dd3 li[data-id=" + id + "]").removeAttr('data-'+formInput[i]);
you need to start using .removeData(). Right now I will leave this PR open, and maybe we will merge it before next big release. Let me know if it helps you.
Instead, replace line 452 with this item = $.extend({}, JSON.parse(JSON.stringify(this.dataset))),