| Author |
Validate at least one checkbox in a Modal Window.
|
c york
Greenhorn
Joined: Mar 16, 2006
Posts: 27
|
|
I have created a Modal Window with several checkboxes. How do I validate at least one was checked?
public class ServicesModalPage extends AuthModalPage {
private AjaxButton commitBtn;
private AjaxButton cancelBtn;
final EntityTO selectedEntity = new EntityTO();
//boolean editFormHasData=false;
//public void setEditFormHasData(boolean editFormHasData) {
// this.editFormHasData = editFormHasData;
//}
ServicesModalPage(final ModalWindow parentModalWindow, final EntityTO selectedEntity) throws VechsDatabaseException {
Form<EntityTO> form = new Form<EntityTO>("mainForm", new CompoundPropertyModel<EntityTO>(selectedEntity));
//ServicesModalPage(mainForm);
add(form);
//Form<EmptyFormTO> form = new Form<EmptyFormTO>("mainForm");
//add(form);
form.add(new CheckBox("cCr"));
form.add(new CheckBox("eCr"));
form.add(new CheckBox("dCr"));
form.add(new CheckBox("cEd"));
form.add(new CheckBox("eEd"));
form.add(new CheckBox("dEd"));
form.add(new CheckBox("cSup"));
form.add(new CheckBox("eSup"));
form.add(new CheckBox("dSup"));
form.add(new CheckBox("cPla"));
form.add(new CheckBox("ePla"));
form.add(new CheckBox("dPla"));
form.add(new CheckBox("cRec"));
form.add(new CheckBox("eRec"));
form.add(new CheckBox("dRec"));
// setEditFormHasData(false);
commitBtn = new AjaxButton("commit") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
parentModalWindow.close(target);
}
@Override
public boolean isVisible() {
return true;
}
};
form.add(commitBtn);
cancelBtn = new AjaxButton("cancel") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
parentModalWindow.close(target);
}
};
cancelBtn.setDefaultFormProcessing(false);
form.add(cancelBtn);
}
}
|
 |
Jeff Friesen
author
Ranch Hand
Joined: Sep 19, 2010
Posts: 41
|
|
Hi C,
You might want to create an array of Checkbox labels and, for each label, add a new Checkbox object with the label to the form:
Assuming that your Form class has a method such as getComponents(), you might do something like this to determine if at least one Checkbox object is selected:
I hope this helps.
Jeff
|
http://javajeff.mb.ca
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
And you may want to UseCodeTags; see how much easier Jeff's post is to read.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Validate at least one checkbox in a Modal Window.
|
|
|