-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi there guru's.
i have a very simple request.
is it possible to have a leading zero in an intbox with a contraint?
ideally I would like to apply this in the zul with minimal java code.
how does one do this?
<intbox id="postalCode" constraint="allow leading zero" width="150px"/>
(ok, allow leading zero doesnt work, i know... just asking for some help here please)
Use the format attribute on the intbox that's inherited from FormatInputElement
I think this is not going to work.
I'd recommend using TypeConverter:
public class PrependZeroConverter implements TypeConverter { public Object coerceToBean(Object aArg0, Component aArg1) { return aArg0; } public Object coerceToUi(Object aArg0, Component aArg1) { return "0".concat(aArg0.toString()); } }
Of course, do some null checks :)
Hi,mixgho
because the type of variable in the setValue method of the zk intbox is int
java int isn't allow leading zero
you can type leading zero value in intbox, but leading zero value will convert to java int, and it not leading zero
maybe you can use textbox and constraint
<textbox constraint="/.[0-9]+/"/>
hi there!
caclark ->thank you for the suggestion, i failed to find a quick solution tho :(
mixgho -> i didnt want to write anything else but apply zul attributes to do this quickly. its just a small thing so i wanted a small solution
as1225 -> i initially had a textbox but later changed it to int box, only to now discover i have funky data in the db... aiyor
anyways, point is, i used as1225 recomendation and using a textbox.
thank you all for the help provided!!
I really appreciate it!!!
If you need a validation for it have a look here.
It would be nice if ZK had a NumberBox, its pretty easy to do in pure javascript:
<HTML> <HEAD> <SCRIPT language=Javascript> <!-- function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } //--> </SCRIPT> </HEAD> <BODY> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar"> </BODY> </HTML>
Asked: 2009-11-16 08:13:19 +0800
Seen: 1,456 times
Last updated: Apr 03 '11