0

dateboxConstraint

asked 2015-07-06 16:38:51 +0800

tess gravatar image tess
5 2

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

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-07 08:26:51 +0800

WilliamB gravatar image WilliamB
1609 1 6

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/

link publish delete flag offensive edit
0

answered 2015-07-07 08:33:21 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9
https://github.com/chillw...

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.

Zul :

<?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>

Java:

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-07-06 16:38:51 +0800

Seen: 18 times

Last updated: Jul 07 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More