fixes : data-value igoned for empty element

This commit is contained in:
vitalets
2013-03-06 13:17:40 +04:00
parent 4d527d7007
commit fcc08b8def
4 changed files with 20 additions and 8 deletions

@ -5,6 +5,7 @@ X-editable changelog
Version 1.4.2 wip Version 1.4.2 wip
---------------------------- ----------------------------
[bug #141] data-value ignored for empty elements (vitalets)
[bug #137] fix empty class for delegated element (vitalets) [bug #137] fix empty class for delegated element (vitalets)
[enh #121] add support of momentjs 2.0.0 in combodate (vitalets) [enh #121] add support of momentjs 2.0.0 in combodate (vitalets)

@ -26,7 +26,7 @@ Makes editable any HTML element on the page. Applied as jQuery method.
//name //name
this.options.name = this.options.name || this.$element.attr('id'); 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); this.input = $.fn.editableutils.createInput(this.options);
if(!this.input) { if(!this.input) {
return; return;
@ -77,9 +77,19 @@ Makes editable any HTML element on the page. Applied as jQuery method.
} }
//check conditions for autotext: //check conditions for autotext:
//if value was generated by text or value is empty, no sense to run autotext switch(this.options.autotext) {
doAutotext = !isValueByText && this.value !== null && this.value !== undefined; case 'always':
doAutotext &= (this.options.autotext === 'always') || (this.options.autotext === 'auto' && !this.$element.text().length); 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() { $.when(doAutotext ? this.render() : true).then($.proxy(function() {
if(this.options.disabled) { if(this.options.disabled) {
this.disable(); this.disable();
@ -241,7 +251,7 @@ Makes editable any HTML element on the page. Applied as jQuery method.
if(this.options.display === false) { if(this.options.display === false) {
return; return;
} }
this.isEmpty = isEmpty !== undefined ? isEmpty : $.trim(this.$element.text()) === ''; this.isEmpty = isEmpty !== undefined ? isEmpty : $.trim(this.$element.text()) === '';
//emptytext shown only for enabled //emptytext shown only for enabled

@ -453,7 +453,7 @@ $(function () {
expect(3); expect(3);
//auto, text->empty, source->array //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, source: groups,
autotext: 'auto' autotext: 'auto'
}), }),

@ -15,8 +15,9 @@ $(function () {
equal(p.find('input[type=text]').attr('placeholder'), 'abc', 'placeholder exists'); equal(p.find('input[type=text]').attr('placeholder'), 'abc', 'placeholder exists');
p.find('.editable-cancel').click(); p.find('.editable-cancel').click();
ok(!p.is(':visible'), 'popover was removed'); ok(!p.is(':visible'), 'popover was removed');
}); });
asyncTest("should load correct value and save new entered text (and value)", function () { asyncTest("should load correct value and save new entered text (and value)", function () {
var v = 'ab<b>"', var v = 'ab<b>"',
esc_v = $('<div>').text(v).html(), esc_v = $('<div>').text(v).html(),