Handsontable - I found a bug when copying/pasting a german numeric value

SuperMario77

I want to use the Javascript grid framework Handsontable for my next project, but I found a small bug, which is a blocking point for using this lib. :-(

I have to show a table with german prices, e.g. "18,50 €". The german language has a , (comma) as decimal point. By default handsontable has only the language "en" for the embedded "numeral.js" helper library. So added the german (de) language definition for numeral.js. The cell format is defined as "0.00 $" and it will show correctly as "18,50 €" in the grid.

But when I select a cell with e.g "1,50 €" (single click on the cell), then press "Ctrl+C" and paste it again with Ctrl+V into another cell. The new cell has the wrong value "15,00 €", because the copied value in the clipboard is "1.5" which then will be pasted as "15".

HTML:

<div id="exampleGrid"></div>

Javascript:

(function () {
    var language = {
        delimiters: {
            thousands: '.',
            decimal: ','
        },
        abbreviations: {
            thousand: 'k',
            million: 'm',
            billion: 'b',
            trillion: 't'
        },
        ordinal: function (number) {
            return '.';
        },
        currency: {
            symbol: '€'
        }
    };
    if (typeof window !== 'undefined' && this.numeral && this.numeral.language)  {
        this.numeral.language('de', language);
    }
}());

$("#exampleGrid").handsontable({
    data: [ [1.5], [] ],
    rowHeaders: true,
    colHeaders: true,
    columns: [
        { type: 'numeric', format: '0.00 $', language: 'de'}
    ]
});

I have created a jsfiddle for demonstrating the problem: http://jsfiddle.net/hU6Kz/4873/

I work with version 0.23.0. I tried a lot to workaround this bug (hooks, custom validators, ...) but nothing helps, because I didn't get the original value "1.5" inside the event callbacks. I only get the wrong value "15". You can see this, when using "beforeChange" hook as additional option in the handsontable constructor:

beforeChange: function (changes, source) {
        for (var i = changes.length - 1; i >= 0; i--) {
            console.log('Changes: source:' + source + ' row:' + changes[i][0] + ' col:' + changes[i][1] + ' old:' + changes[i][2] + ' new:' + changes[i][3]);
        }
    }

When I do the copy and paste of "1,50 €" then the console shows:

Changes: source:paste row:1 col:0 old:null new:15

My idea was to recognize the 1.50 and change it to 1,50 before handsontable updates the cell, but the new value is already "15", so no chance to see the original copied value. :-(

Perhaps someone of you has an idea.

Thanks in advance.

Update:

In the source code I found the function 'validateChanges' which does the following:

if (numeral.validate(changes[i][3])) {
    changes[i][3] = numeral().unformat(changes[i][3]);
}

When the current numeral language is 'de' and call this, the result ist "15". So here is the problem, but how to solve it?

numeral().unformat('1.5 €')

And now I understand, why I didn't get the original copied value when the hook "beforeChange" is called. Because this 'validateChanges' is called before the hook is triggered.

And now?

raszpi

Replace on line 24646:

if (languages[currentLanguage].delimiters.decimal !== '.') {
  string = string.replace(/\./g, '').replace(languages[currentLanguage].delimiters.decimal, '.');
}

With this:

if (languages[currentLanguage].delimiters.decimal !== '.') {
  string = string.replace(languages[currentLanguage].delimiters.decimal, '.');
}

The first string replace removes the decimal point from the raw data.

Note: I'm not that familiar with this js library, this could lead to unintended consequences. Discuss the problem with the project maintainers on their github page.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

fatal error: unexpectedly found nil while unwrapping an Optional value in Swift when tried to parse JSON

来自分类Dev

Is this a Chef/ohai bug when dealing with FQDNs?

来自分类Dev

app crashing when ever i entering negitive value

来自分类Dev

NPM not found when using NVM

来自分类Dev

How to empty a numeric value from a form built with WTForm

来自分类Dev

How to input unicode character and get its numeric value

来自分类Dev

PHP is_numeric vs〜(〜(float)$ value)性能和功能

来自分类Dev

German email resource file

来自分类Dev

完全禁用handsontable

来自分类Dev

在Ember中使用Handsontable

来自分类Dev

完全禁用handsontable

来自分类Dev

获取handsontable的JSON表示

来自分类Dev

Handsontable 创建双标题

来自分类Dev

IE 10 bug with display table CSS when height is 100%?

来自分类Dev

Bug when resizing borderless window with SDL2

来自分类Dev

Socket.io client ignoring port when namespace used [Bug?]

来自分类Dev

How do I find out the numeric ID of the current Postgres Transaction?

来自分类Dev

how to change values with rank value (ordered value) in R? and I want to give same numbers when two values tie

来自分类常见问题

In jQuery, how do I get the value of a radio button when they all have the same name?

来自分类Dev

How can I increment value of the variable when scroll reaches top of the div

来自分类Dev

I need a cell to be filled with a certain text when two other cells contain a certain value

来自分类Dev

Path not found when creating a file-VBA

来自分类Dev

Localization doesn't work for german?

来自分类Dev

隐藏javascript中的handsontable列

来自分类Dev

用Flask保存HandsOnTable数据

来自分类Dev

Handsontable中的访问单元对齐

来自分类Dev

如何使Handsontable中的栏很宽?

来自分类Dev

handsontable onChange()/ afterChange()参数问题

来自分类Dev

用Flask保存HandsOnTable数据

Related 相关文章

  1. 1

    fatal error: unexpectedly found nil while unwrapping an Optional value in Swift when tried to parse JSON

  2. 2

    Is this a Chef/ohai bug when dealing with FQDNs?

  3. 3

    app crashing when ever i entering negitive value

  4. 4

    NPM not found when using NVM

  5. 5

    How to empty a numeric value from a form built with WTForm

  6. 6

    How to input unicode character and get its numeric value

  7. 7

    PHP is_numeric vs〜(〜(float)$ value)性能和功能

  8. 8

    German email resource file

  9. 9

    完全禁用handsontable

  10. 10

    在Ember中使用Handsontable

  11. 11

    完全禁用handsontable

  12. 12

    获取handsontable的JSON表示

  13. 13

    Handsontable 创建双标题

  14. 14

    IE 10 bug with display table CSS when height is 100%?

  15. 15

    Bug when resizing borderless window with SDL2

  16. 16

    Socket.io client ignoring port when namespace used [Bug?]

  17. 17

    How do I find out the numeric ID of the current Postgres Transaction?

  18. 18

    how to change values with rank value (ordered value) in R? and I want to give same numbers when two values tie

  19. 19

    In jQuery, how do I get the value of a radio button when they all have the same name?

  20. 20

    How can I increment value of the variable when scroll reaches top of the div

  21. 21

    I need a cell to be filled with a certain text when two other cells contain a certain value

  22. 22

    Path not found when creating a file-VBA

  23. 23

    Localization doesn't work for german?

  24. 24

    隐藏javascript中的handsontable列

  25. 25

    用Flask保存HandsOnTable数据

  26. 26

    Handsontable中的访问单元对齐

  27. 27

    如何使Handsontable中的栏很宽?

  28. 28

    handsontable onChange()/ afterChange()参数问题

  29. 29

    用Flask保存HandsOnTable数据

热门标签

归档