-
FEATURED COMPONENTS
First time here? Check out the FAQ!
let's say i have two datebox, startDateBox and endDateBox, first i put value inside startDateBox (2/Jan/2013), then i put second value inside endDateBox, now my question is, how to set validation so that endDatebox can't set value before 2/Jan/2013
example :
startDateBox = 2/Jan/2013 endDateBox = can't set value before 2/Jan/2013
btw, sorry for my english
Thanks,
Klepon
If you are using MVVM then below example will be helpful for you.
<zk> <window border="normal" title="hello" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('pkg$.DateValidationViewModel')">
<datebox value="@bind(vm.beginDate)" />
<datebox value="@bind(vm.endDate)" />
<button id="btn" label="Validate"
onClick="@command('validate')" />
</window>
</zk>
DateValidationViewModel.java
import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import java.sql.Timestamp;
import org.zkoss.zul.*;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
public class DateValidationViewModel extends GenericForwardComposer {
private Timestamp beginDate;
private Timestamp endDate;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
@Command
@NotifyChange("*")
public void validate() {
if (beginDate != null && endDate != null && endDate.compareTo(beginDate) < 0) {
endDate = null;
Messagebox.show("End Date can not be less than begin date.");
}
}
public Timestamp getBeginDate() {
return beginDate;
}
public void setBeginDate(Timestamp beginDate) {
this.beginDate = beginDate;
}
public Timestamp getEndDate() {
return endDate;
}
public void setEndDate(Timestamp endDate) {
this.endDate = endDate;
}
}
I have created same example in Fiddle also http://zkfiddle.org/sample/77vhl8/2-Date-Validation#source-2
If you are using MVVM, then I would use a form validator, There is an example in ZK Demo which shows how to do that.
Asked: 2013-04-06 03:32:39 +0800
Seen: 131 times
Last updated: Apr 08 '13
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status
i just figured this out. put this snippet on the code
kleponboy ( 2013-04-08 04:08:49 +0800 )editDid you consider that the end date could be entered first? And that the fields can be edited again in any order? I also tried something similar and ended up with multiple error boxes. Sometimes it was not even possible to get rid of them again.
Matze2 ( 2013-04-08 08:27:35 +0800 )edit