-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I need the following behavior:
I want to format the user supplied value in such a way that it disables characters and adds leading zeros up to 7 digits.
So, if user types in "35" the textbox value should immediately update itself to "0000035".
Is this possible, and how, and is there maybe some alternative that I'm missing?
You can take help from Here/a].
Please provide ZK version because you can write Zscript in ur ZUl page but sometime zscript disable because no one want to use JS if we already using very good framework like ZK.But iw ill suggest you to do server side for security reason.
thanks
Hi jj,
I already used client side events, but for different purposes and components.
The problem is I don't see in the client reference doc that such an event (onChange) is available for textboxes on the client.
Maybe it is somehow implicitly present...?
See this link and point to me what should I use, or what did I miss?
Thanks.
Look at Widget.listen() method and Event description in the client development guide. There are DOM events and Widget Events, and I think you want to listen to widget-level events. I have no first-hand experience with it, so please let me know if it works out.
Lesstra,
I'm sure others here will give you a more elegant way to do this but here is one way:
<zk xmlns:w="client"> <script> function applyMask(compId, val){ var pad = "0000000"; var result = (pad+val).slice(-pad.length); compId = '#' + compId; jQuery(compId).val(result); } </script> <zscript> import org.zkoss.zk.ui.util.GenericForwardComposer; public class MyController extends GenericForwardComposer { Textbox txtbx; public void onChangeTextbox(Event event) { String maskCommand = "applyMask('" + txtbx.getUuid() + "','" + txtbx.getValue() + "')"; Clients.evalJavaScript(maskCommand); } } </zscript> <window id="main" apply="MyController"> <textbox id="txtbx" forward="onChange=onChangeTextbox" onCreate="self.focus();"> <attribute w:name="doKeyPress_"> function(evt){ if (!this._shallIgnore(evt, "0123456789")) this.$doKeyPress_(evt); } </attribute> </textbox> </window> </zk>
Hope that sparks an idea or two.
Regards,
Todd
Asked: 2012-09-14 15:40:09 +0800
Seen: 170 times
Last updated: Sep 18 '12