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

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