You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB

  1. /* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  2. odoo.define("web_decimal_numpad_dot.FieldFloat", function (require) {
  3. "use strict";
  4. var basic_fields = require("web.basic_fields");
  5. var translation = require("web.translation");
  6. var NumpadDotReplaceMixin = {
  7. l10n_decimal_point: function () {
  8. return this.formatType === "float_time"
  9. ? ":" : translation._t.database.parameters.decimal_point;
  10. },
  11. _replaceAt: function (cur_val, from, to, replacement) {
  12. return cur_val.substring(0, from) + replacement +
  13. cur_val.substring(to);
  14. },
  15. _onKeydown: function (event) {
  16. // Only act on numpad dot key
  17. if (event.keyCode !== 110) {
  18. return this._super.apply(this, arguments);
  19. }
  20. event.preventDefault();
  21. var from = this.$input.prop("selectionStart"),
  22. to = this.$input.prop("selectionEnd"),
  23. cur_val = this.$input.val(),
  24. point = this.l10n_decimal_point();
  25. var new_val = this._replaceAt(cur_val, from, to, point);
  26. this.$input.val(new_val);
  27. // Put user caret in place
  28. to = from + point.length;
  29. this.$input.prop("selectionStart", to).prop("selectionEnd", to);
  30. },
  31. };
  32. basic_fields.FieldFloat.include(NumpadDotReplaceMixin);
  33. basic_fields.FieldMonetary.include(NumpadDotReplaceMixin);
  34. return {
  35. NumpadDotReplaceMixin: NumpadDotReplaceMixin,
  36. };
  37. });