[html-formfu] use FormFu::Model::DBIC in Dancer2 app and populate select element in a form

Gert van Oss gertlist at mac.com
Mon Oct 1 13:40:11 GMT 2018


okay, answering my own question after again reading through:

https://metacpan.org/pod/HTML::FormFu::Model::DBIC <https://metacpan.org/pod/HTML::FormFu::Model::DBIC#Config-options-for-options_from_model>

The code below works

get '/add-client' => sub {
    my $form = HTML::FormFu->new;
    $form->load_config_file("forms/addclient.yml");
    $form->model('DBIC');
    $form->stash( schema => $schema );
    $form->process;
    template 'add-client' => { 'myform' => $form };
};


The addcountry.yml part where the element shows up is:
   - type: Block
      tag: tr
      attributes:
        id: country_id
      elements:
      - type: Block
        tag: td
        content_xml: "Land-code *"
        attributes:
          class: label
      - type: Block
        tag: td
        elements:
          type: Select
          name: "country_id"
          model_config:
            resultset: Country
            label_column: "country"


> On Oct 1, 2018, at 13:43PM, Gert van Oss <gertlist at mac.com> wrote:
> 
> hello,
> 
> I’m using HTML::FormFu to generate forms for a small Dancer2 application. Creating the forms all works fine. While trying to experiment with HTML::FormFu::Model::DBIC I got lost.
> 
> With the code shown below the form is generated but the select element doesn’t show any values. Have I missed something?
> 
> Best regards,
> Gert
> 
> 
> The route in the Dancer2 App is:
> 
> ————
> get '/add-client' => sub {
>   my $form = HTML::FormFu->new;
>   $form->model('DBIC');
>   $form->stash( schema => $schema );
>   my $data = LoadFile('forms/addcountry.yml');
>   $form->populate($data);
>   template 'add-country' => { 'myform' => $form };
> };
> ————
> 
> The addcountry.yml part where the element shows up is:
> 
> ————
>  - type: Block
>     tag: tr
>     attributes:
>       id: country_id
>     elements:
>     - type: Block
>       tag: td
>       content_xml: "Land-code *"
>       attributes:
>         class: label
>     - type: Block
>       tag: td
>       elements:
>         type: Select
>         name: "country_id"
>         model_config:
>           resultset: Country
> ————
> 
> 
> 
> 
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20181001/bebd9c0a/attachment.htm>


More information about the HTML-FormFu mailing list