I wonder if it's the best way to stick the entire processing to the 
"input" event. As you write, it is done for every character typed in. 
Maybe you want to make sure you only get legal characters in the field, 
so that should probably happen on "input". But I would only *format* 
after the user finishes (I as a user would find it weird if input gets 
formatted while I'm typing it). That would mean attaching the formatting 
action to e.g. the "blur" event.

T.

On 10/03/2011 03:04 PM, Marco Pompili wrote:
> 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
>
>

------------------------------------------------------------------------------
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