mirror of https://github.com/OCA/web.git
[FIX] web_widget_char_switchcase: keep caret position
parent
a32d65bd9b
commit
4752f6dc6f
|
@ -3,7 +3,7 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
{
|
{
|
||||||
"name": "Web Char Switchcase Widget",
|
"name": "Web Char Switchcase Widget",
|
||||||
"version": "10.0.1.0.1",
|
"version": "10.0.1.0.2",
|
||||||
"author": "Agile Business Group, "
|
"author": "Agile Business Group, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
|
|
|
@ -21,9 +21,18 @@ odoo.define('web_widget_char_switchcase', function (require) {
|
||||||
console.error(this.current_transformation + ' case unknown');
|
console.error(this.current_transformation + ' case unknown');
|
||||||
},
|
},
|
||||||
_onKeyUp: function (event) {
|
_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 old_val = this.$input.val();
|
||||||
var new_val = this.current_transformation_handler(old_val);
|
var new_val = this.current_transformation_handler(old_val);
|
||||||
this.$input.val(new_val);
|
this.$input.val(new_val);
|
||||||
|
|
||||||
|
// restore caret position
|
||||||
|
input.setSelectionRange(start, end);
|
||||||
},
|
},
|
||||||
parse_value: function (val, def) {
|
parse_value: function (val, def) {
|
||||||
return this._super(this.current_transformation_handler(val), def);
|
return this._super(this.current_transformation_handler(val), def);
|
||||||
|
|
|
@ -4,6 +4,7 @@ odoo.define_section('web_widget_char_switchcase', ['web.form_common', 'web.core'
|
||||||
function createField(form_common, web_form_widgets, node) {
|
function createField(form_common, web_form_widgets, node) {
|
||||||
var field_manager = new form_common.DefaultFieldManager(null, {});
|
var field_manager = new form_common.DefaultFieldManager(null, {});
|
||||||
var fieldWidget = new web_form_widgets.FieldChar(field_manager, node);
|
var fieldWidget = new web_form_widgets.FieldChar(field_manager, node);
|
||||||
|
fieldWidget.setElement($('<input/>'));
|
||||||
fieldWidget.initialize_content();
|
fieldWidget.initialize_content();
|
||||||
return fieldWidget;
|
return fieldWidget;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue