[html-formfu] Config::General "select" form field

Carl Franks fireartist at gmail.com
Tue Dec 16 17:04:55 GMT 2008


2008/12/15 Florent Angly <florent.angly at gmail.com>:
> Hi all,
> I have trouble creating Config::General code for a form select field. For
> example, how does the following YAML config translate into Config::General?
>>
>> elements:
>>  - type: Select
>>    name: sex
>>    options:
>>      - [ 'm', 'Male' ]
>>      - [ 'f', 'Female' ]
>
> I've tried many syntaxes without success. Thanks for your help,

You can use a combination of YAML and Data::Dumper to convert the yaml to perl:
$ perl -MYAML=LoadFile -MData::Dumper -le 'print
Dumper(LoadFile(q{config.yml}))'

$VAR1 = {
          'elements' => [
                          {
                            'options' => [
                                           [
                                             'm',
                                             'Male'
                                           ],
                                           [
                                             'f',
                                             'Female'
                                           ]
                                         ],
                            'name' => 'sex',
                            'type' => 'Select'
                          }
                        ]
        };

Hopefully that'll help you write it in Config::General syntax.
(I can't answer your question directly, as I don't use Config::General)

If those arrays in options() cause problems, you could also use the
following form:

$VAR1 = {
          'elements' => [
                          {
                            'options' => [
                                           {
                                             'value' => 'm',
                                             'label' => 'Male'
                                           },
                                           {
                                             'value' => 'f',
                                             'label' => 'Female'
                                           }
                                         ],
                            'name' => 'sex',
                            'type' => 'Select'
                          }
                        ]
        };


Carl



More information about the HTML-FormFu mailing list