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.

50 lines
1.6 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. init: function () {
  8. this.events = $.extend({}, this.events, {
  9. "keydown": "numpad_dot_replace",
  10. });
  11. return this._super.apply(this, arguments);
  12. },
  13. l10n_decimal_point: function () {
  14. return this.widget == "float_time"
  15. ? ":" : translation._t.database.parameters.decimal_point;
  16. },
  17. numpad_dot_replace: function (event) {
  18. // Only act on numpad dot key
  19. if (event.keyCode != 110) {
  20. return;
  21. }
  22. event.preventDefault();
  23. var from = this.$input.prop("selectionStart"),
  24. to = this.$input.prop("selectionEnd"),
  25. cur_val = this.$input.val(),
  26. point = this.l10n_decimal_point();
  27. // Replace selected text by proper character
  28. this.$input.val(
  29. cur_val.substring(0, from) +
  30. point +
  31. cur_val.substring(to)
  32. );
  33. // Put user caret in place
  34. to = from + point.length
  35. this.$input.prop("selectionStart", to).prop("selectionEnd", to);
  36. },
  37. };
  38. basic_fields.FieldFloat.include(NumpadDotReplaceMixin);
  39. basic_fields.FieldMonetary.include(NumpadDotReplaceMixin);
  40. return {
  41. NumpadDotReplaceMixin: NumpadDotReplaceMixin,
  42. };
  43. });