Today I implemented some basic input restrictions for the number
formatter. Now the textfield only accept numbers, sign characters,
thousand separators and decimals.
Currently is just basic infrastructure. It's possible to go around the
restrictions by pasting external text, for example, or to create an
invalid number by deleting the first digit in "0.33". Those restrictions
can be implemented later but for now I'd like to focus on creating more
formatters.
But right now the implementation works great for the common cases in
Firefox and Explorer ;).
Feedback is appreciated!
--
Ing. Leonardo Quijano Vincenzi
DTQ Software
Leonardo Quijano Vincenzi wrote:
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.
-------------------------------------------------------
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