diff --git a/addons/mail/static/src/js/field_char.js b/addons/mail/static/src/js/field_char.js new file mode 100644 index 00000000000..1a1b90ec875 --- /dev/null +++ b/addons/mail/static/src/js/field_char.js @@ -0,0 +1,56 @@ +odoo.define('sms.onchange_in_keyup', function (require) { +"use strict"; + +var FieldChar = require('web.basic_fields').FieldChar; +FieldChar.include({ + + //-------------------------------------------------------------------------- + // Public + //------------------------------------------------------------------------- + + /** + * Support a key-based onchange in text field. In order to avoid too much + * rpc to the server _triggerOnchange is throttled (once every second max) + * + */ + init: function () { + this._super.apply(this, arguments); + this._triggerOnchange = _.throttle(this._triggerOnchange, 1000, {leading: false}); + }, + + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Trigger the 'change' event at key down. It allows to trigger an onchange + * while typing which may be interesting in some cases. Otherwise onchange + * is triggered only on blur. + * + * @override + * @private + */ + _onKeydown: function () { + this._super.apply(this, arguments); + if (this.nodeOptions.onchange_on_keydown) { + this._triggerOnchange(); + } + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Triggers the 'change' event to refresh the value. Throttled at init to + * avoid spaming server. + * + * @private + */ + _triggerOnchange: function () { + this.$input.trigger('change'); + }, +}); + +}); diff --git a/addons/mail/views/assets.xml b/addons/mail/views/assets.xml index 09aff4897af..f582e344010 100644 --- a/addons/mail/views/assets.xml +++ b/addons/mail/views/assets.xml @@ -11,6 +11,7 @@ + diff --git a/addons/sms/wizard/sms_composer_views.xml b/addons/sms/wizard/sms_composer_views.xml index 543b731f360..b1be27ca32b 100644 --- a/addons/sms/wizard/sms_composer_views.xml +++ b/addons/sms/wizard/sms_composer_views.xml @@ -45,7 +45,7 @@ attrs="{'invisible': [('comment_single_recipient', '=', False)]}"/>
- +