I've come up with a solution with this, well almost.

I'm using this RegExp: /(\d+\.?)*(\,\d{0,2})?/

To restrict the input i don't use a filter anymore, but I execute the
expression above and get the matched string.

In the Parser function:
// Get the string with restricted input
var match = this.getRegexp().exec(string)[0];

In the constructor there's only an event definition that binds parser and
formatter.

this.addListener("input", function(data)
{
        this.setValue(this.format(this.parse(data.getData())));
}, this);

So if an user try to use a character that doesn't match the  RegExp, the
textfield is not updated, like it should happen with a setFilter, but with
the filter only one character at time is checked and not the entire
expression (for what i've seen).

So the logic is basically this one:

The parser function check the Match array generated by the exec Function of
RegExp and parse the number removing the dots inserted by the formatting
function. Then sends the cleaned number to the format function that formats
again the number.

[ Parser ] -> Check the RegExp and sends a clean number without dots.
      |
[ Formatter ] -> Format the cleaned number applying the dots accordingly to
the new number.
      |
[ this.setValue ]-> Then set the value of the field.

This transaction occurs on every input event (character added or removed in
the textfield).

I got some problems with Chrome now, the problem is that when a dot is
inserted the text cursor doesn't move at the end of the field, but remains
in the same place. Like this:

1.000.000| <- text cursor

10.000.00|0 <- text cursor in the same place and not at the end.

When i've solved these crossbrowsing problems i'll post a contribution. 

-----
La coincidenza non ha madre.
--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Number-formatting-and-separators-tp6776330p6854909.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to