-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I want to set constraint for datebox This is an example I found in zk tutorials for between dates, <datebox constraint="between 20071225 and 20071203"/>
but I want my constraint to be such that the user can't be more than 13 years i.e: I want to subtract the birth date from current date and can't be less than 13 years old
How can I do that using constraint = " "
Thanks in advance Tess
Not sure if the constraint attribut accept EL. You can however do a custom constraint : http://books.zkoss.org/wiki/ZK_Component_Reference/Base_Components/InputElement#Custom_Constraint (http://books.zkoss.org/wiki/ZKComponentReference/BaseComponents/InputElement#CustomConstraint)
And here is an exemple how to pass parameter to your constraint (haven't tested myself) : http://forum.zkoss.org/question/51273/parameterizing-constraint/
Hello Tess.
You have to work woith your viewmodel to get a date that is 13 years ago.
This fiddle shows how you can do it.
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.DateboxViewModel')">
<datebox id="date1" format="dd/MM/yyyy" constraint="@load(c:cat('no empty, before ',vm.maxDate))"/>
</vlayout>
public class DateboxViewModel {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
public String getMaxDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -13);
return dateFormat.format(cal.getTime());
}
}
Greetz chill.
Asked: 2015-07-06 16:38:51 +0800
Seen: 18 times
Last updated: Jul 07 '15