Yii Framework Forum: HTML formatting for checkBoxList() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

HTML formatting for checkBoxList() Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,003
  • Joined: 30-October 09
  • Location:UK

Posted 04 December 2009 - 10:34 AM

By default the checkBoxList generates a default formatting, I want it to generate custom formatting as follows:

(for each checkbox:)

<tr>
    <td class="label"><label for="index">value</label></td>

    <td><input type="checkbox" id="index" /></td>
</tr>

1

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,003
  • Joined: 30-October 09
  • Location:UK

Posted 05 December 2009 - 06:49 PM

Can anyone help me with this please?
0

#3 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 05 December 2009 - 07:08 PM

View PostGSTAR, on 04 December 2009 - 10:34 AM, said:

By default the checkBoxList generates a default formatting, I want it to generate custom formatting as follows:

(for each checkbox:)

<tr>
    <td class="label"><label for="index">value</label></td>

    <td><input type="checkbox" id="index" /></td>
</tr>



Is this what you want to do? (The generated attributes ar still the same)
echo CHtml::checkBoxList('...','...', array(...),
  array('template'=>'<tr><td >{label}</td><td>{input}</td></tr>')
);


/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
3

#4 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,003
  • Joined: 30-October 09
  • Location:UK

Posted 07 December 2009 - 06:00 AM

Cheers mate, that's done the job perfectly.
0

#5 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,003
  • Joined: 30-October 09
  • Location:UK

Posted 11 December 2009 - 09:46 AM

Anybody know how can I split this checkBoxList and display it in two columns (side by side)? Is there any function in Yii that can do this?
0

#6 User is offline   trevor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 22-December 08

Posted 15 December 2009 - 08:57 AM

View PostGSTAR, on 11 December 2009 - 09:46 AM, said:

Anybody know how can I split this checkBoxList and display it in two columns (side by side)? Is there any function in Yii that can do this?



Did anyone figure out how to display the checkboxlist as two columns?

Thanks
0

#7 User is offline   Ricardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 20-August 09
  • Location:Warsaw, Poland

Posted 16 December 2009 - 06:43 AM

Two columns? You mean something like:

label checkbox
label checkbox
label checkbox

or

label checkbox label checkbox
label checkbox label checkbox
label checkbox label checkbox

?
0

#8 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,003
  • Joined: 30-October 09
  • Location:UK

Posted 16 December 2009 - 07:11 AM

Your second example.

I kind of figured out how to do it, I had to use a foreach loop and generate the checkboxes manually. So in other words I was unable to do it using the checkBoxList method. It would have been nice if there was a built in functionality in Yii to acheive this.
0

#9 User is offline   trevor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 22-December 08

Posted 16 December 2009 - 07:17 AM

View PostGSTAR, on 16 December 2009 - 07:11 AM, said:

Your second example.

I kind of figured out how to do it, I had to use a foreach loop and generate the checkboxes manually. So in other words I was unable to do it using the checkBoxList method. It would have been nice if there was a built in functionality in Yii to acheive this.


This is the direction I went in as well.
0

#10 User is offline   Ricardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 20-August 09
  • Location:Warsaw, Poland

Posted 16 December 2009 - 09:31 AM

I think there is no need to achieve that using checkBoxList. CheckBoxList is simply a list. You have template option to modify standard template and that's it. If you need to achieve something different you build your own solution using single checkbox. In my opinion this is the best way to keep it simple.
0

#11 User is offline   JamesBarnsley 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 414
  • Joined: 18-November 10
  • Location:UK

Posted 25 June 2011 - 12:29 PM

View PostRicardo, on 16 December 2009 - 09:31 AM, said:

I think there is no need to achieve that using checkBoxList. CheckBoxList is simply a list. You have template option to modify standard template and that's it. If you need to achieve something different you build your own solution using single checkbox. In my opinion this is the best way to keep it simple.


Hmm well I like to keep things simple, but I think the Yii CheckBoxList should have something that allows for multiple columns.

Or at least get rid of the last "<br />" after each checkbox so we can float them left.
0

#12 User is offline   Pronskiy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-August 11

Posted 22 August 2011 - 06:58 AM

View PostJamesBarnsley, on 25 June 2011 - 12:29 PM, said:

Or at least get rid of the last "<br />" after each checkbox so we can float them left.


You can get rid of those '<br />'s by specifying 'separator' option like this

echo CHtml::checkBoxList('...','...', array(...),
  array(
    'separator'=>'',
    )
);

0

#13 User is offline   phpguy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 24-April 11
  • Location:Myrtle Beach, SC

Posted 29 August 2011 - 01:27 PM

Example of Pronskiy's & JamesBarnsley's advice:

<div class="checkboxgroup">
<?php 
	echo CHtml::checkBoxList('...','...', array(...),
	  array(
	    'separator'=>'',
	    'template'=>'<div>{input}&nbsp;{label}</div>'
	    )
	);	
?>
</div>

<style>
.checkboxgroup{
	overflow:auto;
}
.checkboxgroup div{
	width:200px;
	float:left;
}
</style>

Life can only be understood backwards; but it must be lived forwards.
1

#14 User is offline   Marian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-February 12

Posted 23 March 2012 - 01:44 PM

Hello guys,

I am trying to use checkboxlist, but it inserts all the labels and inputs into a span. How can I remove that span ?


Kind Regards,

Marian
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users