Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Validate at least one checkbox in a Modal Window.

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}

 
author
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you may want to UseCodeTags; see how much easier Jeff's post is to read.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic