Forums / Developer / How to create multi checkbox like multi option?

How to create multi checkbox like multi option?

Author Message

sangib das

Wednesday 18 October 2006 4:14:55 am

Hi
I want to create a class named food.Which contain the following information.......

1.How many food do u like?(quetion )

[ ] Chicken Biriyani
[ ] Chicken Kabab
[ ] Eggs Biriyani
and so on.

When it will be dipaly to user side the user must select as mush as he like.
Thank and regards
Sangib

Nabil Alimi

Wednesday 18 October 2006 5:08:25 am

Hi Sangdib,

Just une an ezselection datatype into your class with "multiple" as select method. Then create an override for your datatype.

This should do.

http://ez.no/doc/ez_publish/technical_manual/3_6/reference/template_override_conditions

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

sangib das

Wednesday 18 October 2006 5:42:38 am

Hi Nabil Alimi
Thanks for help but it is not working.
no check box is not coming like that
only one valu is coming Chicken biriyani.
Thanks and Regards
Sangib

Xavier Dutoit

Wednesday 18 October 2006 7:22:03 am

Hi,

If you need things like being able to retrieve how many time a food as been selected and the al, Try
http://ez.no/community/contribs/datatypes/enhanced_objectrelation

Selection list check box.

X+

http://www.sydesy.com

Claudia Kosny

Thursday 19 October 2006 11:30:51 am

Hello Sangib

EDIT: I just realised that I most likely misunderstood your question. So please clarify first:
Do you want to have checkboxes where your customer just can check whether he wants to have a certain meal or not or do you want to have an input fields where the user can say he wants to have a certain meal 5 times?
If you want the checkboxes, my comments below should help you, if you want the inputfields the only idea I would have is to use products and add them to the basket a certain amount of times. /EDIT

What does your template look like?

Here an general idea of what you need to do:
The edit view of an ezselection is usually displayed using the template \templates\content\datatype\edit\ezselection.tpl

Now create an override for it so it displays checkboxes instead of an drowdown box. Get rid of the select tag and change the foreach so that you have checkboxes:
<input type="checkbox" name="{$attribute_base}_ezselect_selected_array_{$attribute.id} value="{$item.id}" {if $selected_id_array|contains($item.id)}checked="checked"{/if} /> {$item.name|wash( xhtml )}

Please note that if you override the ezselection template, all selections will be displayed as checkboxes. If you don't want that you can put the code with the checkboxes directly into the template code which edits the object, if you need more info on that just ask.

Claudia

sangib das

Friday 20 October 2006 1:53:39 am

Hi Claudia Kosny,
Thanks a lot .But now i am doing one thing given below

(ADMIN SECTION)

1 I created a class called poll
2 this class only consist of ezoption datatype
3 Create a folder named Poll
4 Under this folder I created a object like that
Who is your favourite player?(question)
1.Sachi Tendul kar
2.Sanath joysuriya
3.Mahendra sing Dhani
Ther is one Add option butoon using that we can create as much as we wnat to add other name.

(USER SITE)
In the user side it is displaying

Who is your favourite player
O Sachin
O Sanath Jaysuriya
O Mahen Drasing Dhani

from here user can only select only one answer.................

But Now my question is that i will allow the user to select multiple answes.so i edited the
file given below

file name
ezpublish-3.8.4/design/standard/templates/content/datatype/collect/ezoption.tpl

{default attribute_base=ContentObjectAttribute}
{let selected_id_array=cond( is_set( $#collection_attributes[$attribute.id] ), $#collection_attributes[$attribute.id].content, $attribute.content )}
{section var=Options loop=$attribute.class_content.options}

<input type="checkbox" name="{$attribute_base}_ezselect_selected_array_{$attribute.id}[]"

value="{$Options.item.id}" {section show=$selected_id_array|contains( $Options.item.id )}selected="selected"{/section}/>{$Options.item.name|wash( xhtml )}
{/section}

{/let}
{/default}

pls give me some suggestion whether it is possible or not.

Thanks and regars
Sangib

Claudia Kosny

Friday 20 October 2006 4:04:06 pm

Hi Sangib

I can see two problems:
I haven't worked much with ezoptions yet but as there is an extra datatype for multioption I doubt that the ezoption datatype can be used for multiple selection. And you definitely do not want the multioption - this is really useful only in the webshop. I would recommend using the ezselection datatype for your needs. Here you can specify in the class definition where a multiple select should be allowed or not. You can also use ezselection as information collector.

In case you really can use ezoption for multiple selects, the name of the checkboxes is still wrong. The checkboxes must have exactly the same name as the selectbox in the original template. Your checkboxes are names as if they belong to an ezselection which does not work when you have an ezoption datatype.

Greetings from Luxembourg

Claudia

laurent le cadet

Tuesday 06 March 2007 7:33:31 am

To Claudia,

I'm trying to display ezselection as checkboxes in a template.
Could you help me based on your example?

Reagrds.

Laurent

Claudia Kosny

Tuesday 06 March 2007 10:39:40 am

Hi Laurent

I haven't tested this, but hre the way I would try:
This is the relevant part of the original standard\templates\content\datatype\collect\ezselection.tpl:

<select name="{$attribute_base}_ezselect_selected_array_{$attribute.id}[]">
{section var=Options loop=$attribute.class_content.options}
<option value="{$Options.item.id}" {section show=$selected_id_array|contains( $Options.item.id )}selected="selected"{/section}>{$Options.item.name|wash( xhtml )}</option>
{/section}
</select>

Instead of the options you want to have checkboxes. Therefore the checkboxes need to have the same name as the select:

{section var=Options loop=$attribute.class_content.options}
 <input type="checkbox" name="{$attribute_base}_ezselect_selected_array_{$attribute.id}[]" value="{$Options.item.id}"{section show=$selected_id_array|contains( $Options.item.id )} checked="checked"{/section} />{$Options.item.name|wash( xhtml )}<br />
{/section}

For consistency's sake I have used the section loop and the section show, but you should rather use foreach and if instead. As usual the above is not tested, so there might be some typos in there.

Please note that checkboxes make only sense if you have allowed multiple selection in your ezselection attribute. Otherwise you should use radiobuttons instead.

Claudia