Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate at least one checkbox in a Modal Window.

 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you may want to UseCodeTags; see how much easier Jeff's post is to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic