From 8992b7751c626a30fd188473400ed43951c26b35 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 14 Mar 2017 10:53:34 +0100 Subject: [ADD] web: add boolean field tests and documentation --- addons/web/static/src/js/fields/basic_fields.js | 42 ++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index ec0c161e4e4..f4f5496006c 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -283,11 +283,22 @@ var FieldBoolean = AbstractField.extend({ // Public //-------------------------------------------------------------------------- + /** + * Automatically selects the field. + * + * @override + */ activate: function () { this.$input.focus(); setTimeout(this.$input.select.bind(this.$input), 0); }, - isSet: function () { + + /** + * A boolean field is always set since false is a valid value. + * + * @override + */ + isSet: function () { return true; }, @@ -295,11 +306,28 @@ var FieldBoolean = AbstractField.extend({ // Private //-------------------------------------------------------------------------- + /** + * The actual checkbox is designed in css to have full control over its + * appearance, as opposed to letting the browser and the os decide how + * a checkbox should look. The actual input is disabled and hidden. + * + * @override + * @private + */ _renderReadonly: function () { var $checkbox = this._formatValue(this.value); this.$input = $checkbox.find('input'); this.$el.empty().append($checkbox); }, + + /** + * The actual checkbox is designed in css to have full control over its + * appearance, as opposed to letting the browser and the os decide how + * a checkbox should look. The actual input is hidden. + * + * @override + * @private + */ _renderEdit: function () { this._renderReadonly(); this.$input.prop('disabled', false); @@ -309,10 +337,22 @@ var FieldBoolean = AbstractField.extend({ // Handlers //-------------------------------------------------------------------------- + /** + * Properly update the value when the checkbox is (un)ticked to trigger + * possible onchanges. + * + * @private + */ _onChange: function () { this._setValue(this.$input[0].checked); }, + /** + * Implement keyboard movements. Mostly useful for its environment, such + * as a list view. + * + * @override + * @private * @param {KeyEvent} event */ _onKeydown: function (event) { -- cgit v1.2.3