Again with the issue of the masks,

I think I'm getting closer to what I actually want with masked fields. The problem with MaskEdit implementation is that it is too rigid, and doesn't allow for additional formatting or an arbitrary number of characters in your input string. For example, you couldn't enter a number like "356787363.39" and want to implement a masked field for this.

I implemented a different approach, using pluggable "formatters". I don't know how much code I'm repeating here, but since this is a proof-of-concept, I thought it would be nice.
These formatters would follow a general contract like this (in Javascript):

formatter.format(str) -> formatted string.
formatter.validate(str) -> is the string valid?
formatter.isValid(previousStr, nextStr, char) -> test to see if the "char" can be inserted between "previousStr" and "nextStr".

I implemented a test NumberFormatter (though the "isValid" char method is still pending), and the general idea is that Tacos binds "onchange" events to format(str) (as long as the text is valid), and in the future (maybe tomorrow) it will bind mask events ("onkeypress", "onpaste", etc) to the isValid(previousStr, nextStr, char), to test whether a char can be inserted or not in the field. To use it, we would put something like this in a Tapestry page template:

         <input jwcid="[EMAIL PROTECTED]"
formatter='"number;decimal=,;separator=.;roundedPlaces=2"'
                    value="ognl:numberEuropean"
                    displayName="Number (European)" />

(Using the "formatter" render contribution).

Right now the number formatter is successfully formatting numbers with customizable decimal and thousand separators, and number signs. It's in MasksExample.html if anyone wants to check it out ;). In the future I'd like to bind the input restrictions (to allow only numbers to enter, and only in the correct spots), and maybe even integrating this with server-side translators.

--
Ing. Leonardo Quijano Vincenzi
DTQ Software




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Tacos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tacos-devel

Reply via email to