diff --git a/grunt.js b/grunt.js index 74c98ea..e7427c9 100644 --- a/grunt.js +++ b/grunt.js @@ -100,7 +100,7 @@ module.exports = function(grunt) { //module for testing var module = ''; - module = '&module=textarea'; +// module = '&module=textarea'; //module = '&module=select'; //module = '&module=text'; diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 3d17d69..6047336 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -109,16 +109,20 @@ Makes editable any HTML element on the page. Applied as jQuery method. @method render() */ render: function() { - //if it is input with source, we pass callback in third param to be called when source is loaded - if(this.input.options.hasOwnProperty('source')) { - return this.input.value2html(this.value, this.$element[0], this.options.display); - //if display method defined --> use it - } 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]); - } + //do not display anything + if(this.options.display === false) { + return; + } + //if it is input with source, we pass callback in third param to be called when source is loaded + if(this.input.options.hasOwnProperty('source')) { + return this.input.value2html(this.value, this.$element[0], this.options.display); + //if display method defined --> use it + } 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) */ handleEmpty: function () { + //do not handle empty if we do not display anything + if(this.options.display === false) { + return; + } + var emptyClass = 'editable-empty'; //emptytext shown only for enabled if(!this.options.disabled) { @@ -547,12 +556,13 @@ Makes editable any HTML element on the page. Applied as jQuery method. value: null, /** 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. Second parameter __sourceData__ is passed for inputs with source (select, checklist). @property display - @type function + @type function|boolean @default null @since 1.2.0 @example diff --git a/test/unit/text.js b/test/unit/text.js index ad500ff..fa236ec 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -479,6 +479,30 @@ $(function () { start(); }, 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); + + }); }); \ No newline at end of file