Re: [Cppcms-users] rendering list of widgets::checkbox
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2011-03-10 12:09:22
|
Hello, First of all all widgets are not copyable so you can't put them to STL containers! The simplest way is to call form::attach(...) and add them dynamically to the form as pointers (ownership is transferred to the form object) Then you can render them as <% foreach box in my_form.list_of_pointers_to_checkboxes %> <ul> <% item %> <li><% form as_space *box %></li> <% end %> </ul> <% end %> Each one independently or you can use a sub form that you add all dynamic widgets to it and render them in one command <% from as_ul my_form.chckboxes_subform %> For example: class my_form : public cppcms::form{ cppcms::form checkboxes; // Subform std::vector<cppcms::widgets::checkox *> boxes; my_form() { add(checkboxes); // register to parent for(int i=0;i<n;i++) { cppcms::widgets::checkox *box = new cppcms::widgets::checkox(); checkboxes.attach(box); // transfer ownership and register to parent box->message(...) boxes.push_back(box); } } } Rendering <% from as_ul my_form.checkboxes %> Take a look on this as example: http://cppcms.svn.sourceforge.net/viewvc/cppcms/blog/trunk/views/admin/post.tmpl?revision=1690&view=markup http://cppcms.svn.sourceforge.net/viewvc/cppcms/blog/trunk/data/admin/post.h?revision=1690&view=markup http://cppcms.svn.sourceforge.net/viewvc/cppcms/blog/trunk/apps/admin/post.cpp?revision=1691&view=markup Artyom ----- Original Message ---- > From: augustin <aug...@ov...> > To: cpp...@li... > Sent: Thu, March 10, 2011 9:37:25 AM > Subject: [Cppcms-users] rendering list of widgets::checkbox > > > Hello Artyom, > > I have a form with a series of checkboxes. The number of checkboxes is > variable and know at run time. > > I figured I could use a std::list of widgets::checkbox, and declare that >within > > my form struct, but I am wondering how to render this in the template: > http://art-blog.no- > ip.info/wikipp/en/page/cppcms_1x_templates_comm#Rendering.Forms > > Will cppcms iterate itself over any STL class like a list or a map? > A form containing simple widgets is easy enough to render: > <% form as_p info %> > but how would that look like if the form includes a std::list of widgets? > > Thanks, > > Augustin. > > > > > > -- > Friends: http://www.reuniting.info/ > My projects: > http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ > > > http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ > http://openteacher.info/ http://minguo.info/ > http://www.wechange.org/ http://searching911.info/ > > > > > > > > > > > > > . > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |