Yii Framework Forum: Checkbox List Pre-Selected On Update - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Checkbox List Pre-Selected On Update Rate Topic: -----

#1 User is offline   newbee to php 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 25-June 13

Posted 17 October 2013 - 05:09 AM

guys....
this is the code that i have in my view

<div class="row">
        <?php echo $form->labelEx($model, 'technology'); ?>
    <ul><?php echo CHtml::activeCheckboxList($model, 'technology',CHtml::listData(Technology::model()->findAll(), 'tech_id', 'tech_name'),array('template'=>'<li>{label}{input}</li>'));?>
        <div class="clearleft"></div>
    </ul>
        <?php echo $form->error($model, 'technology'); ?>
    
    </div>



while creating i have stored the data from checkboxes in the database using implode.
i want the check box list to be pre selected when i go to the update form.
how can i do it?
0

#2 User is offline   faridplus 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 93
  • Joined: 28-March 12

Posted 18 October 2013 - 05:00 AM

Hi, I don't quite understand this part of your question:

View Postnewbee to php, on 17 October 2013 - 05:09 AM, said:

....
while creating i have stored the data from checkboxes in the database using implode.
....


Why would you use implode?! it's true that you have multiple check boxes in your form but when the form is submitted only a single value will be returned and you should save 1 value in your db so there is no need for implode. If you do this then CHtml::activeCheckboxList() can select the right checkbox automatically.
What you give is what you get (WYGIWYG)

If you liked my post, just give it a +1. that's all!
0

#3 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 08-October 12
  • Location:Austria

Posted 18 October 2013 - 03:54 PM

View Postnewbee to php, on 17 October 2013 - 05:09 AM, said:

guys....
this is the code that i have in my view

<div class="row">
        <?php echo $form->labelEx($model, 'technology'); ?>
    <ul><?php echo CHtml::activeCheckboxList($model, 'technology',CHtml::listData(Technology::model()->findAll(), 'tech_id', 'tech_name'),array('template'=>'<li>{label}{input}</li>'));?>
        <div class="clearleft"></div>
    </ul>
        <?php echo $form->error($model, 'technology'); ?>
    
    </div>



while creating i have stored the data from checkboxes in the database using implode.
i want the check box list to be pre selected when i go to the update form.
how can i do it?


Hi

did u added this in your rule method?
array('technology', 'boolean')

Then its get saved.. then it will automatically works as you expect :)
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#4 User is offline   newbee to php 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 25-June 13

Posted 25 October 2013 - 06:34 AM

View Postchandran, on 18 October 2013 - 03:54 PM, said:

Hi

did u added this in your rule method?
array('technology', 'boolean')

Then its get saved.. then it will automatically works as you expect :)


Thanks for your rep guyzzz
0

#5 User is offline   GSTAR 

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

Posted 25 October 2013 - 05:35 PM

Have you tried this in your controller:

$model = $this->loadModel();

$model->technology = explode(", ", $model->technology);

0

#6 User is offline   SrikanthMaggidi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-May 14
  • Location:Hyderabad,India

Posted 21 May 2014 - 05:36 AM

follow this

http://www.yiiframew...__1#entry250478


Thanks,
Srikanth
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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