From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/mail/static/src/js/field_char.js | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 addons/mail/static/src/js/field_char.js (limited to 'addons/mail/static/src/js/field_char.js') 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 00000000..1a1b90ec --- /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'); + }, +}); + +}); -- cgit v1.2.3