-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello, i am trying to add a validation in java depending on the values from the back end.
For example, if the field's "type" value is 1, then i want the field "identity" to accept numbers only, otherwise, ot can hold any letter. I've tried to add an attribute to the field in my backend like:
((Textbox) identity).setAttribute("onKeyDown", "/*some js here to allow numbers only*/");
but it does not work.
By the way, this event fires on a "onChange" method from a combobox.
Thanks.
[Edit] Added some sample code
public void onChangeSelect (@ContextParam(ContextType.VIEW) Component view) {
Component txtNumCI = view.query("#id");
if (param == 1) {
((Textbox) txtNumCI).setMaxlength(8);
} else {
((Textbox) txtNumCI).setMaxlength(11);
}
}
So, when combobox "type" changes and sets the param value to 1 or 0 (simplified), then maxlength is changed as in sample code, but it should also validate if the value is numbers only (when param = 1) or alphanumeric otherwise.
Why don't you just check for your "backend" and add a textbox
or intbox
depending the case.
With MVVM this could be done with the visible attribute, or zk 8 the if tag.
Looks like you use MVVM =>
So what about this :
<intbox value="@bind(vm.value)" if="${vm.param eq 1}" maxlength="8" />
<textbox value="@bind(vm.value)" if="${vm.param ne 1}"maxlength="11" />
Greetz chill.
Asked: 2016-06-07 22:34:58 +0800
Seen: 57 times
Last updated: Jun 09 '16
Placeholder with phonemasking in IE11 Browser not working
Facing issue in masking on phone [closed]
coerceFromString_ override no longer works from 6.5.1 [closed]
Execute Javascript on component visible
Is there a way to resolve view model properties as input to client side javascripts?
scrollbar listner for 2 grid [closed]
I can not comment on @chillworld answer, but the idea is to use dynamic client validation so that i don't have to say "it will validate it later", i don't know how to accomplish this with the visible attribute?
jvilcayp ( 2016-06-08 14:46:21 +0800 )editMvvm pattern? Otherwise show small part of your zul and Java code how you build up your screen
chillworld ( 2016-06-08 17:29:56 +0800 )edit@chillworld, added some simplified sample code of how it is currently handled (as of today, the validation of numbers only or alphanum is handled on form submit)
jvilcayp ( 2016-06-08 19:25:06 +0800 )edit