Wednesday, April 27, 2011

Re: Can't set checkbox "checked" with FormHelper

http://www.dereuromark.de/2010/06/23/working-with-forms/
"default values"

On 27 Apr., 19:23, lsiden <lsi...@gmail.com> wrote:
> Slight correction.  The "hardcoded" attempt _does_ work.   There was a
> logic error so a different branch was getting executing.
>
> $this->Form->checkbox('Equipment.collect', array(
>                                         'checked' => true, //
> $equip['collect'],
>                                       ))
>
> However, the "auto-magic" creation of the checkbox with "checked" set
> still won't work.
>
> On Apr 27, 1:14 pm, lsiden <lsi...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I wrote a view that generates a form.  One of the fields is defined in
> > the database as "tinyint(1)" (aka "bool").  FormHelper->input()
> > correctly renders a checkbox for this field, but does not set it to
> > checked, even when the value is 1.
>
> >  <?= $this->Form->input($field, array(
> >                                         'value' => $equip[$field]
> > ['value'],
> >     ));
> > //pr($equip[$field]);
> >   ?>
>
> > Here is the output of the above "pr()" call when it's un-commented:
>
> > Array
> > (
> >     [value] => 1
> > )
>
> > I tried to trace through the code, and think that the problem is in
> > Helper->value(), which always returns null in this case.
>
> > Do I have to treat "bool" checkboxes as a special case?
>
> > Even this won't initialize the checkbox as checked:
>
> > $this->Form->checkbox('Equipment.collect', array(
> >                                         'checked' => true, //
> > $equip['collect'],
> >                                       ))

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: