display: false, element text does not change

This commit is contained in:
vitalets
2012-12-06 16:12:07 +04:00
parent c2f18b108d
commit 2341854e15
3 changed files with 48 additions and 14 deletions

@ -100,7 +100,7 @@ module.exports = function(grunt) {
//module for testing //module for testing
var module = ''; var module = '';
module = '&module=textarea'; // module = '&module=textarea';
//module = '&module=select'; //module = '&module=select';
//module = '&module=text'; //module = '&module=text';

@ -109,16 +109,20 @@ Makes editable any HTML element on the page. Applied as jQuery method.
@method render() @method render()
*/ */
render: function() { render: function() {
//if it is input with source, we pass callback in third param to be called when source is loaded //do not display anything
if(this.input.options.hasOwnProperty('source')) { if(this.options.display === false) {
return this.input.value2html(this.value, this.$element[0], this.options.display); return;
//if display method defined --> use it }
} else if(typeof this.options.display === 'function') { //if it is input with source, we pass callback in third param to be called when source is loaded
return this.options.display.call(this.$element[0], this.value); if(this.input.options.hasOwnProperty('source')) {
//else use input's original value2html() method return this.input.value2html(this.value, this.$element[0], this.options.display);
} else { //if display method defined --> use it
return this.input.value2html(this.value, this.$element[0]); } else if(typeof this.options.display === 'function') {
} return this.options.display.call(this.$element[0], this.value);
//else use input's original value2html() method
} else {
return this.input.value2html(this.value, this.$element[0]);
}
}, },
/** /**
@ -207,6 +211,11 @@ Makes editable any HTML element on the page. Applied as jQuery method.
* set emptytext if element is empty (reverse: remove emptytext if needed) * set emptytext if element is empty (reverse: remove emptytext if needed)
*/ */
handleEmpty: function () { handleEmpty: function () {
//do not handle empty if we do not display anything
if(this.options.display === false) {
return;
}
var emptyClass = 'editable-empty'; var emptyClass = 'editable-empty';
//emptytext shown only for enabled //emptytext shown only for enabled
if(!this.options.disabled) { if(!this.options.disabled) {
@ -547,12 +556,13 @@ Makes editable any HTML element on the page. Applied as jQuery method.
value: null, value: null,
/** /**
Callback to perform custom displaying of value in element's text. Callback to perform custom displaying of value in element's text.
If not defined, default input's value2html() will be called. If <code>null</code>, default input's value2html() will be called.
If <code>false</code>, no displaying methods will be called, element's text will no change.
Runs under element's scope. Runs under element's scope.
Second parameter __sourceData__ is passed for inputs with source (select, checklist). Second parameter __sourceData__ is passed for inputs with source (select, checklist).
@property display @property display
@type function @type function|boolean
@default null @default null
@since 1.2.0 @since 1.2.0
@example @example

@ -479,6 +479,30 @@ $(function () {
start(); start();
}, timeout); }, timeout);
}); });
asyncTest("display: false", function () {
var newText = 'cd<e>;"',
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1" data-value="abc"></a>').appendTo(fx).editable({
display: false
});
ok(!e.text().length, 'element still empty, autotext did not display value');
e.click()
var p = tip(e);
p.find('input').val(newText);
p.find('form').submit();
setTimeout(function() {
ok(!p.is(':visible'), 'popover was removed');
ok(!e.text().length, 'element still empty, new value was not displayed');
equal(e.data('editable').value, newText, 'new text saved to value');
e.remove();
start();
}, timeout);
});
}); });