Kris,
Sorry for the late reply I didn't see your post. Yes I have it
working, a little different than you. Hit me up on irc if you want to
talk about it. Basically what I did was create nested schemas
dynamically inside my form. Works pretty well.
On Jun 26, 3:57 pm, Kris Wallsmith <[EMAIL PROTECTED]> wrote:
> Hm, I have this working, but I think another widget class is called
> for. Something like sfWidgetFormSelectManyCheckbox (that's a
> mouthful). At least having "checkbox" in the class name will help our
> web designer friends see what's going on...
>
> class myForm extends sfForm
> {
> public function configure()
> {
> $choices = array();
> foreach (CategoryPeer::doSelect(new Criteria) as $category)
> {
> $choices[$category->getId()] = $category->getName();
>
> }
>
> $this->setWidgets(array(
> 'category_id[]' => new sfWidgetFormSelectRadio(array('choices' =>
> $choices), array('type' => 'checkbox')),
> ));
>
> //etc.........
>
> On Jun 26, 2:45 pm, Kris Wallsmith <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi Ian,
>
> > Did you ever get anywhere on this? I'm trying to create a checkbox
> > list like this...
>
> > <ul>
> > <li><input type="checkbox" name="category[]" value="1"
> > id="category_1" /> <label for="category_1">My category 1</label></li>
> > <li><input type="checkbox" name="category[]" value="2"
> > id="category_2" /> <label for="category_2">My category 2</label></li>
> > </ul>
>
> > Like you, I can't figure out how to implement this with the core
> > widgets...
>
> > Kris
>
> > On Jun 3, 9:58 am, "Slick Rick" <[EMAIL PROTECTED]> wrote:
>
> > > Fabien,
>
> > > Thanks. I was able to figure this out by creating a new sfWidgetFormSchema
> > > inside the form. One more question. Why can I not set the "value" of
> > > acheckbox? This seemed to be the best option, but still didn't work:
>
> > > new sfWidgetFormInputCheckbox(array(), array('value' => $value));
>
> > > Any reason why I can't set the value?
>
> > > Thanks,
>
> > > -- Ian
>
> > > ----- Original Message -----
> > > From: "Fabien Potencier" <[EMAIL PROTECTED]>
> > > To: <[email protected]>
> > > Sent: Tuesday, June 03, 2008 2:31 AM
> > > Subject: [symfony-devs] Re:Dynamiccheckboxarrays for sfForms in 1.1
>
> > > You can manipulate the widget and validator schemas as if they were
> > > arrays... except they are not. Instead of creating an array, you need to
> > > create a sfWidgetSchema, which behaves like an array.
>
> > > So, in your case, you have 2 options:
>
> > > * Create a form for your collection of widgets and embed it: symfony
> > > will do the ground work for you
> > > * Do everything by hand
>
> > > Here is an example for the first option:
>
> > > <?php
>
> > > class ThingForm extends sfForm
> > > {
> > > public function configure()
> > > {
> > > // ...
>
> > > $this->embedForm('group', new checkboxesCollectionForm());
> > > }
> > > }
>
> > > class checkboxesCollectionForm extends sfForm
> > > {
> > > public function configure()
> > > {
> > > foreach (array('foo', 'bar') as $value)
> > > {
> > > $this->widgetSchema[$value] = new sfWidgetFormInputCheckbox();
> > > $this->validatorSchema[$value] = new sfValidatorPass();
> > > }
> > > }
> > > }
>
> > > I've attached a screenshot for this example.
>
> > > And here is the exact same example but you do everything by yourself:
>
> > > <?php
>
> > > class ThingForm extends sfForm
> > > {
> > > public function configure()
> > > {
> > > // ...
>
> > > $this->widgetSchema['group'] = new sfWidgetFormSchema();
> > > $this->validatorSchema['group'] = new sfValidatorSchema();
> > > foreach (array('foo', 'bar') as $value)
> > > {
> > > $this->widgetSchema['group'][$value] = new
> > > sfWidgetFormInputCheckbox();
> > > $this->validatorSchema['group'][$value] = new sfValidatorPass();
> > > }
> > > }
> > > }
>
> > > If you want to use the <?php echo $form ?> statement, you will have to
> > > decorate the collection like this:
>
> > > $this->widgetSchema['group'] = new
> > > sfWidgetFormSchemaDecorator($this->widgetSchema['group'],
> > > $this->widgetSchema['group']->getFormFormatter()->getDecoratorFormat());
>
> > > Fabien
>
> > > Ian wrote:
> > > > One additional note. It's often common to have one "label" for the
> > > > entire collection of checkboxes. So i'd like to be able to do this as
> > > > well.
>
> > > > On Jun 2, 5:16 pm, "Slick Rick" <[EMAIL PROTECTED]> wrote:
> > > >> I'm trying to create adynamiclist of "groups", that can be selected via
> > > >> checkboxes. What is the best way to create this "collection"
> > > >> ofcheckbox
> > > >> widgets in my form class so it is handled by the rendering engine as
> > > >> well
> > > >> as validation and error handling?
>
> > > >> I tried to do this:
>
> > > >> foreach ($groups as $group)
> > > >> {
> > > >> $schema['group'][] = new sfWidgetFormInputCheckbox(array(),
> > > >> array('value' => $group['id']));
>
> > > >> }
>
> > > >> ... but when I try to render it, it tells me Widget "group" does not
> > > >> exist. Even if try to echo $form['group'][0]->render(). Same error.
>
> > > >> Is there some internal mechanism that can handle groups of form
> > > >> elements
> > > >> properly?
>
> > > >> Thanks for any help...
>
> > > >> -- Ian
>
> > > --
> > > Fabien Potencier
> > > Sensio CEO - symfony lead developer
> > > sensiolabs.com | symfony-project.com | aide-de-camp.org
> > > Tél: +33 1 40 99 80 80
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---