[html-formfu] How do I set selected option programatically?

Dennis Daupert ddaupert at gmail.com
Fri May 15 19:27:21 GMT 2009


I found the documentation on setting a Select default,
but not on how to set 'selected' on a select option
on the fly.

My yml config file configures three selects:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
---
# indicator is the field that is used to test for form submission
indicator: submit
# Start listing the form elements
auto_fieldset:
  legend: Add Entry
elements:
   - type: Select
     name: project_id
     label: 'Projects (optional)'
     empty_first: 1
     model_config:
        resultset: Projects
        condition:
           active: 1
   - type: Select
     name: status_id
     label: Status
     empty_first: 1
     model_config:
        resultset: Statuses
        condition:
           active: 1
   - type: Select
     name: assignee
     label: Assignee
     empty_first: 1
     model_config:
        resultset: Users
        condition:
           active: 1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

I need to set options on the fly for those selects.

In my Catalyst app, I have this code (attempting to select the
option thru the default method. If this should work, I must
have the format wrong.):

    # Pre-populate selects
    my $fieldset =3D $form->get_element({ type =3D> 'Fieldset' });

    my $proj_select =3D $fieldset->get_element({type =3D> 'Select',
                                              name =3D> 'project_id'});
    $proj_select->default($project_id) if $project_id;

    my $stat_select =3D $fieldset->get_element({type =3D> 'Select',
                                              name =3D> 'status_id'});
    $stat_select->default($status_id) if $status_id;

    my $assign_select =3D $fieldset->get_element({type =3D> 'Select',
                                                name =3D> 'assignee'});
    $assign_select->default($assignee) if $assignee;

I do have confirmation that the variables are populated:
$project_id, $status_id, $assignee.

/dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090515/0f=
269657/attachment.htm


More information about the HTML-FormFu mailing list