[html-formfu] Config::General "select" form field
Florent Angly
florent.angly at gmail.com
Wed Dec 17 10:48:59 GMT 2008
Carl Franks wrote:
> 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
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
Exactly Carl! Using the alternate way worked. The Config::General code
looks like that:
<elements>
name sex
type Select
<options>
value m
label Male
</options>
<options>
value f
label Female
</options>
</elements>
Thanks for your help. Best,
Florent
More information about the HTML-FormFu
mailing list