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
----------------------------
[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)

@ -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

@ -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'
}),

@ -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(),