diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 88f2048..c1fbe1f 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ X-editable changelog Version 1.4.6 wip ---------------------------- +[bug #312] can't apply selector more than once (vitalets) [enh #48] textarea: use `white-space: pre-wrap` instead of nl2br conversion (vitalets) [enh #286] added HTML5 time input (Doggie52) [enh] add `defaultValue` option (vitalets) diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 72a3efa..92cdd9b 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -621,6 +621,14 @@ Makes editable any HTML element on the page. Applied as jQuery method. data = $this.data(datakey), options = typeof option === 'object' && option; + //for delegated targets do not store `editable` object for element + //it's allows several different selectors. + //see: https://github.com/vitalets/x-editable/issues/312 + if(options && options.selector) { + data = new Editable(this, options); + return; + } + if (!data) { $this.data(datakey, (data = new Editable(this, options))); } diff --git a/test/unit/common.js b/test/unit/common.js index 53ee13f..2079f02 100644 --- a/test/unit/common.js +++ b/test/unit/common.js @@ -647,13 +647,19 @@ test("`selector` option", function () { var parent = $('<div><a href="#" id="a" data-type="text">123</a></div>').appendTo('#qunit-fixture').editable({ - selector: 'a', - url: 'post.php', - source: groups + selector: '#a', + url: 'post.php' }), b = $('<a href="#" id="b" data-type="select" data-value="1"></a>'), e = $('#a'), selected = 2; + + //apply delegated editable second time + parent.editable({ + selector: '#b', + url: 'post.php', + source: groups + }); ok(!e.hasClass('editable'), 'no editable class applied');