diff options
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 10 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 17 |
2 files changed, 23 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 7278e45dedb..725a237750d 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -168,18 +168,20 @@ var AbstractField = Widget.extend({ * part can be disabled. In that case, note that the focused input/textarea * will have the cursor at the very end. * - * @param {boolean} [noselect=false] if false and the input is of type text - * or textarea, the content will also be selected + * @param {Object} [options] + * @param {boolean} [noselect=false] if false and the input + * is of type text or textarea, the content will also be selected + * @param {Event} [options.event] the event which fired this activation * @returns {boolean} true if the widget was activated, false if the * focusable element was not found or invisible */ - activate: function (noselect) { + activate: function (options) { var $focusable = this.getFocusableElement(); if ($focusable.length && $focusable.is(':visible')) { $focusable.focus(); if ($focusable.is('input[type="text"], textarea')) { $focusable[0].selectionStart = $focusable[0].selectionEnd = $focusable[0].value.length; - if (!noselect) { + if (options && !options.noselect) { $focusable.select(); } } diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 3e9ea89be31..6fc1736870f 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -582,6 +582,23 @@ var FieldBoolean = AbstractField.extend({ //-------------------------------------------------------------------------- /** + * Toggle the checkbox if it is activated due to a click on itself. + * + * @override + */ + activate: function (options) { + var activated = this._super.apply(this, arguments); + // The formatValue of boolean fields renders HTML elements similar to + // the one rendered by the widget itself. Even though the event might + // have been fired on the non-widget version of this field, we can still + // test the presence of its o_checkbox class. + if (activated && options && options.event && $(options.event.target).parents('.o_checkbox').length) { + this._setValue(!this.value); // Toggle the checkbox + } + return activated; + }, + + /** * @override * @returns {jQuery} the focusable checkbox input */ |
