Thanks Derrel and Fritz!

I tried to implement what Derrell said, below is my code. At first glance
all works fine, but sometimes changeValue event isn't raised, I think it
because of I change the value inside handler of changeValue event (maybe
not...). For example, try to input "12...". Can you help me?

The code is
http://demo.qooxdoo.org/devel/playground/#%7B%22code%22%3A%22qx.Class.define%28%2522MoneyTextField%2522%252C%2520%257B%250A%2520%2520extend%2520%253A%2520qx.ui.form.TextField%252C%250A%2520%2520construct%2520%253A%2520function%28%29%2520%257B%250A%2520%2520%2520%2520this.base%28arguments%29%253B%250A%2520%2520%2520%2520this.setLiveUpdate%28true%29%253B%250A%2520%2520%2520%2520this.setFilter%28%252F%255B0-9%255D%257C%255C.%252F%29%253B%250A%2520%2520%2520%2520this.addListener%28%2522changeValue%2522%252C%2520function%28e%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%252F%252Falert%28%2522value%2520changed%2522%29%253B%250A%2520%2520%2520%2520%2520%2520var%2520value%2520%253D%2520this.getValue%28%29%253B%250A%2520%2520%2520%2520%2520%2520if%2520%28this.needResetValue%28value%29%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520this.setValue%28this.__previousValue%29%253B%250A%2520%2520%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%2520%2520this.__previousValue%2520%253D%2520this.getValue%28%29%253B%250A%2520%2520%2520%2520%257D%252C%2520this%29%253B%250A%2520%2520%257D%252C%250A%2520%2520members%2520%253A%2520%257B%250A%2520%2520%2520%2520__previousValue%2520%253A%2520null%252C%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520needResetValue%2520%253A%2520function%28value%29%2520%257B%250A%2520%2520%2520%2520%2520%2520if%2520%28value%2520%253D%253D%253D%2520null%2520%257C%257C%2520value%2520%253D%253D%253D%2520undefined%29%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520false%253B%250A%2520%2520%2520%2520%2520%2520var%2520result%2520%253D%2520false%253B%250A%2520%2520%2520%2520%2520%2520%252F%252Fallow%2520only%2520one%2520dot%253A%250A%2520%2520%2520%2520%2520%2520if%2520%28value.indexOf%28%27.%27%29%2520!%253D%2520value.lastIndexOf%28%27.%27%29%29%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520result%2520%253D%2520true%253B%250A%2520%2520%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%2520%2520%250A%2520%2520%2520%2520%2520%2520%252F%252Fallow%2520only%25202%2520digits%2520after%2520dot%253A%250A%2520%2520%2520%2520%2520%2520var%2520dotIndex%2520%253D%2520value.indexOf%28%2522.%2522%29%253B%250A%2520%2520%2520%2520%2520%2520if%2520%28dotIndex%2520!%253D%2520-1%29%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520var%2520countAfterDot%2520%253D%2520%28value.substring%28dotIndex%252B1%252C%2520value.length%29%29.length%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520if%2520%28countAfterDot%2520%253E%25202%29%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520result%2520%253D%2520true%253B%250A%2520%2520%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%2520%2520return%2520result%253B%250A%2520%2520%2520%2520%257D%250A%2520%2520%257D%250A%257D%29%253B%250A%252F%252F---------------------------------------------------%250Avar%2520txt%2520%253D%2520new%2520MoneyTextField%28%29%253B%250Athis.getRoot%28%29.add%28txt%252C%250A%257B%250A%2520%2520left%2520%253A%2520100%252C%250A%2520%2520top%2520%2520%253A%252050%250A%257D%29%253B%22%2C%20%22mode%22%3A%22ria%22%7D

Derrell Lipman wrote:
> 
> On Mon, Aug 8, 2011 at 08:31, 
> 
> A regular expression can certainly match what you're discussing:
> 
> /[0-9]+([0-9]{2})?/
> 
> but the "filter" regular expression matches each single character, not the
> entire entered text, so no, it can't. You can expand on Gabriel's example,
> which uses the filter and the changeValue event. If you set the
> "liveUpdate"
> property to true, then the changeValue property will be fired on each key
> press. (There is also an "input" event which is always fired on each key
> press.) I don't think there's a way at this level to prevent the character
> from being added to the field, so what you need to do is keep track of the
> value of the field, and if the new character entered is not allowed, then
> reset the field back to its previous value.
> 
> Derrell
> 


--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Keyinput-event-tp6663993p6667044.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to