diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6235762..51d2a31 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ X-editable changelog Version 1.4.2 wip ---------------------------- +[bug #141] data-value ignored for empty elements (vitalets) [bug #137] fix empty class for delegated element (vitalets) [enh #121] add support of momentjs 2.0.0 in combodate (vitalets) diff --git a/src/element/editable-element.js b/src/element/editable-element.js index d83e428..10a4366 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -26,7 +26,7 @@ Makes editable any HTML element on the page. Applied as jQuery method. //name this.options.name = this.options.name || this.$element.attr('id'); - //create input of specified type. Input will be used for converting value, not in form + //create input of specified type. Input need already here to convert value for initial display (e.g. show text by id for select) this.input = $.fn.editableutils.createInput(this.options); if(!this.input) { return; @@ -77,9 +77,19 @@ Makes editable any HTML element on the page. Applied as jQuery method. } //check conditions for autotext: - //if value was generated by text or value is empty, no sense to run autotext - doAutotext = !isValueByText && this.value !== null && this.value !== undefined; - doAutotext &= (this.options.autotext === 'always') || (this.options.autotext === 'auto' && !this.$element.text().length); + switch(this.options.autotext) { + case 'always': + doAutotext = true; + break; + case 'auto': + //if element text is empty and value is defined and value not generated by text --> run autotext + doAutotext = !$.trim(this.$element.text()).length && this.value !== null && this.value !== undefined && !isValueByText; + break; + default: + doAutotext = false; + } + + //depending on autotext run render() or just finilize init $.when(doAutotext ? this.render() : true).then($.proxy(function() { if(this.options.disabled) { this.disable(); @@ -241,7 +251,7 @@ Makes editable any HTML element on the page. Applied as jQuery method. if(this.options.display === false) { return; } - + this.isEmpty = isEmpty !== undefined ? isEmpty : $.trim(this.$element.text()) === ''; //emptytext shown only for enabled diff --git a/test/unit/select.js b/test/unit/select.js index cb5cb20..93a0321 100644 --- a/test/unit/select.js +++ b/test/unit/select.js @@ -453,7 +453,7 @@ $(function () { expect(3); //auto, text->empty, source->array - var e = $('<a href="#" data-type="select" data-value="3"></a>').appendTo(sfx).editable({ + var e = $('<a href="#" data-type="select" data-value="3"> </a>').appendTo(sfx).editable({ source: groups, autotext: 'auto' }), diff --git a/test/unit/text.js b/test/unit/text.js index 7ab83c6..46fdb01 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -15,8 +15,9 @@ $(function () { equal(p.find('input[type=text]').attr('placeholder'), 'abc', 'placeholder exists'); p.find('.editable-cancel').click(); ok(!p.is(':visible'), 'popover was removed'); - }); - + }); + + asyncTest("should load correct value and save new entered text (and value)", function () { var v = 'ab<b>"', esc_v = $('<div>').text(v).html(),