diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7c17193..035888d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,7 +4,8 @@ X-editable changelog Version 1.1.1 wip ---------------------------- -[enh] object can be passed in 'option' method to set several options simultaneously (vitalets) +[enh] 'showbuttons' option to hide buttons in form (vitalets) +[enh] object can be passed in 'option' method to set several options at once (vitalets) [enh #20] toggle editable by 'dblclick' and 'mouseenter' (vitalets) [enh] added 'inputs-ext' directory with sample input 'address'. They will not be concatenated to main files (vitalets) [enh #13] 'onblur' option: to cancel, submit or ignore when user clicks outside the form (vitalets) diff --git a/README.md b/README.md index f7f61c2..aa774c1 100644 --- a/README.md +++ b/README.md @@ -56,11 +56,11 @@ Or use grunt's _qunit_ task <code>grunt test</code>. For that you also need to [ 5.To build lib + docs: * run <code>grunt build</code> in **lib** directory -* run <code>build data-docs-dist-zip</code> in **gh-pages** directory +* run <code>build data-docs-dist</code> in **gh-pages** directory You will get distributive in **lib/dist** and updated docs in **gh-pages/*.html**. Do not edit **index.html** and **docs.html** directly! Instead look at [Handlebars](https://github.com/wycats/handlebars.js) templates in **generator/templates**. -6.Commit changes on <code>dev</code> branch and make pull request as usual. +6.Commit changes on <code>dev</code> / <code>gh-pages-dev</code> branch and make pull request as usual. Thanks for your support! diff --git a/src/editable-form/editable-form-bootstrap.js b/src/editable-form/editable-form-bootstrap.js index 50f72bb..3388544 100644 --- a/src/editable-form/editable-form-bootstrap.js +++ b/src/editable-form/editable-form-bootstrap.js @@ -5,11 +5,8 @@ Editableform based on Twitter Bootstrap $.extend($.fn.editableform.Constructor.prototype, { initTemplate: function() { - this.$form = $($.fn.editableform.template); - this.$form.find('.editable-error-block').addClass('help-block'); - - //buttons - this.$form.find('div.editable-buttons').append($.fn.editableform.buttons); + this.$form = $($.fn.editableform.template); + this.$form.find('.editable-error-block').addClass('help-block'); } }); diff --git a/src/editable-form/editable-form-jqueryui.js b/src/editable-form/editable-form-jqueryui.js index 804b6d2..9f0ea9e 100644 --- a/src/editable-form/editable-form-jqueryui.js +++ b/src/editable-form/editable-form-jqueryui.js @@ -4,10 +4,7 @@ Editableform based on jQuery UI (function ($) { $.extend($.fn.editableform.Constructor.prototype, { - initTemplate: function() { - this.$form = $($.fn.editableform.template); - - //buttons + initButtons: function() { this.$form.find('.editable-buttons').append($.fn.editableform.buttons); this.$form.find('.editable-submit').button({ icons: { primary: "ui-icon-check" }, @@ -17,7 +14,6 @@ Editableform based on jQuery UI icons: { primary: "ui-icon-closethick" }, text: false }).removeAttr('title'); - } }); diff --git a/src/editable-form/editable-form.js b/src/editable-form/editable-form.js index a4b7514..7373ec7 100644 --- a/src/editable-form/editable-form.js +++ b/src/editable-form/editable-form.js @@ -34,9 +34,9 @@ Editableform is linked with one of input types, e.g. 'text' or 'select'. }, initTemplate: function() { this.$form = $($.fn.editableform.template); - - //buttons - this.$form.find('div.editable-buttons').append($.fn.editableform.buttons); + }, + initButtons: function() { + this.$form.find('.editable-buttons').append($.fn.editableform.buttons); }, /** Renders editableform @@ -47,8 +47,14 @@ Editableform is linked with one of input types, e.g. 'text' or 'select'. this.$loading = $($.fn.editableform.loading); this.$element.empty().append(this.$loading); this.showLoading(); - + + //init form template and buttons this.initTemplate(); + if(this.options.showbuttons) { + this.initButtons(); + } else { + this.$form.find('.editable-buttons').remove(); + } /** Fired when rendering starts @@ -431,7 +437,26 @@ Editableform is linked with one of input types, e.g. 'text' or 'select'. @type object @default null **/ - ajaxOptions: null + ajaxOptions: null, + /** + Wether to show buttons or not. + Form without buttons can be submitted by Enter (depends on input), by onblur = 'submit' or manually (via submit api method) + + @property showbuttons + @type boolean + @default true + **/ + showbuttons: true, + /** + Submit strategy. Can be <code>normal|never</code> + <code>submit='never'</code> usefull for turning into classic form several inputs and submitting them together manually. + Works pretty with <code>showbuttons=false</code> + + @property submit + @type string + @default normal + **/ + submit: 'normal' }; /* diff --git a/test/unit/common.js b/test/unit/common.js index 0edd2d8..61e6658 100644 --- a/test/unit/common.js +++ b/test/unit/common.js @@ -345,7 +345,20 @@ e.hover(); p = tip(e); ok(p.is(':visible'), 'popover1 visible after second hover'); - }); + }); + + test("showbuttons: false", function () { + var e = $('<a href="#" id="a"></a>').appendTo('#qunit-fixture').editable({ + showbuttons: false + }); + + e.click(); + var p = tip(e); + ok(p.is(':visible'), 'popover visible'); + ok(!p.find('.editable-submit').length, 'submit not rendered'); + ok(!p.find('.editable-cancel').length, 'cancel not rendered'); + ok(!p.find('.editable-buttons').length, '.editable-buttons block not rendered'); + }); //unfortunatly, testing this feature does not always work in browsers. Tested manually. /*