Browse Source

[FIX] web_widget_char_switchcase: keep caret position

pull/1085/head
Simone Rubino 6 years ago
committed by SimoRubi
parent
commit
4752f6dc6f
  1. 2
      web_widget_char_switchcase/__manifest__.py
  2. 9
      web_widget_char_switchcase/static/src/js/web_widget_char_switchcase.js
  3. 1
      web_widget_char_switchcase/static/test/web_widget_char_switchcase.js

2
web_widget_char_switchcase/__manifest__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Web Char Switchcase Widget",
"version": "10.0.1.0.1",
"version": "10.0.1.0.2",
"author": "Agile Business Group, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",

9
web_widget_char_switchcase/static/src/js/web_widget_char_switchcase.js

@ -21,9 +21,18 @@ odoo.define('web_widget_char_switchcase', function (require) {
console.error(this.current_transformation + ' case unknown');
},
_onKeyUp: function (event) {
// save caret position
var input = this.$input[0];
var start = input.selectionStart;
var end = input.selectionEnd;
// transform the value
var old_val = this.$input.val();
var new_val = this.current_transformation_handler(old_val);
this.$input.val(new_val);
// restore caret position
input.setSelectionRange(start, end);
},
parse_value: function (val, def) {
return this._super(this.current_transformation_handler(val), def);

1
web_widget_char_switchcase/static/test/web_widget_char_switchcase.js

@ -4,6 +4,7 @@ odoo.define_section('web_widget_char_switchcase', ['web.form_common', 'web.core'
function createField(form_common, web_form_widgets, node) {
var field_manager = new form_common.DefaultFieldManager(null, {});
var fieldWidget = new web_form_widgets.FieldChar(field_manager, node);
fieldWidget.setElement($('<input/>'));
fieldWidget.initialize_content();
return fieldWidget;
}

Loading…
Cancel
Save