2

I'm trying to understand the data-structure required to populate a form with 'select' element values (options).

When I dump (Data::Dumper) the FormFu object, I see that the object structure looks similar to the following:

'name' => 'EmailDL',
'_options' => [
         {
           'label_attributes' => {},
           'value' => 'm',
           'container_attributes' => {},
           'label' => 'Male',
           'attributes' => {}
         },
         {
           'label_attributes' => {},
           'value' => 'f',
           'container_attributes' => {},
           'label' => 'Female',
           'attributes' => {}
         }
       ],

Seeing this, I figured that the way to structure $form_input (being that $form_input = \%cgivars) would be something like the following:

     'Firstname' => 'Faisal',
     'EmailDL' => [
                    {
                      'value' => 'myvalue',
                      'label' => 'mylabel'
                    }
                  ],

However this doesn't seem to work. I've found that structuring $form_input correctly, and then issuing a $fu->default_values($form_input) to be simple and effective, except in this instance when I'm trying to include the select/options sub-structure.

So the question is: How should I structure 'EmailDL' above to correctly populate 'select' options when doing $fu->default_values($form_input) or $fu->process($form_input)?

CanSpice
  • 34,814
  • 10
  • 72
  • 86
jbobbylopez
  • 257
  • 2
  • 6
  • 15

1 Answers1

1

To set the options you use the options call,

$fu->get_all_element('EmailDL')->options([ [ 'myvalue', 'mylabel' ], 
                                             [ 'val2', 'label2' ] ]);

If you then want to set one of those values you can use the default_values.

$fu->default_values({ EmailDL => 'val2' });

Further help is available here in the Element::Group documentation. Note the code examples are in the text of the help.

Colin Newell
  • 3,073
  • 1
  • 22
  • 36