[html-formfu] FormFu many_to_many YAML declaration

Robyn Jonahs learn.catalyst at gmail.com
Wed Apr 11 22:59:36 GMT 2012


Thanks. My perl and Catalyst is pretty weak so I apologize for not
understanding how to modify the form in the controller. Well in concept
from the docs, yes, but it seems to say that it can be done.

For the books example in the tutorial they use a select form element, due
to the fact that authors can have many books and books can have many
authors.

BUT

http://search.cpan.org/~pshangov/HTML-FormFu-Model-DBIC-0.09002/lib/HTML/Fo=
rmFu/Model/DBIC.pm#has_many_and_many_to_many_relationships

The section just above the link you sent was what I was trying to use  as a
guide. I do see that they use a Textarea not a Text field. I tried that and
it also failed. With all my trial and error I have yet to figure out where
I am going wrong. The example at the documentation for
HTML::FormFu::Model::DBIC does not use a join table, that was the only
difference I noted from trying to do it with the tutorial. I guess that
section in the documentation won't let me give up yet. The following also
seems to indicate that it is possible to set this up in a Repeatable text
element.

http://search.cpan.org/~perler/HTML-FormFu-0.09007/lib/HTML/FormFu/Element/=
Repeatable.pm


I can see the authors in the stash from the object that we chained to and
set form to in the tutorial.

(controller)
    # Get the specified record already saved by the 'object' method
    my $product =3D $c->stash->{object};

(template)
    [% object.authors.last_name %],
# for Single author or
  Author List:
  [% FOREACH item IN object.authors %]
    , [%- item.full_name -%]
  [%- END -%].

(YAML config)
# EXPERIMENTAL ELEMENTS
#
    - type: Hidden
      name: author_count

    - type: Repeatable
      nested_name: book_authors
      counter_name: author_count
      elements:
        - type: Hidden
          name: book

        - type: Text
          name: author_id
          label: Book Author(s)
          model_config:
            empty_rows: 1

    - type: Text
      name: author
      label: Authors

    # Add a drop-down list for the author selection.  Note that we will
    # dynamically fill in all the authors from the controller but we
    # could manually set items in the drop-list by adding this YAML code:
    # options:
    #   - [ '1', 'Bastien' ]
    #   - [ '2', 'Nasseh'  ]
    - type: Select
      name: authors
      label: Author
      # Convert the drop-down to a multi-select list
      multiple: 1
      # Display 3 entries (user can scroll to see others)
      size: 5
      # One could argue we don't need to do filters or constraints for
      # a select list, but it's smart to do validation and sanity
      # checks on this data in case a user "hacks" the input
      # Add constraints to the field
      constraints:
        # Make sure it's a number
        - Integer

Everything else is set up just as in the tutorial.

I just can't find what is happening or why things are not happening.



On Wed, Apr 11, 2012 at 4:15 PM, Gabor HALASZ <halasz.g at freemail.hu> wrote:

> On 4/11/2012 7:29 PM, Robyn Jonahs wrote:
>
>  |
>> What if I don't want the authors in a select field but a text field? Can
>> I do that?
>>
>>
>> I have been trying to use something like in
>> http://search.cpan.org/~**pshangov/HTML-FormFu-Model-**
>> DBIC-0.09002/lib/HTML/FormFu/**Model/DBIC.pm#has_many_and_**
>> many_to_many_relationships<http://search.cpan.org/%7Epshangov/HTML-FormF=
u-Model-DBIC-0.09002/lib/HTML/FormFu/Model/DBIC.pm#has_many_and_many_to_man=
y_relationships>
>>  <http://search.cpan.org/%**7Epshangov/HTML-FormFu-Model-**
>> DBIC-0.09002/lib/HTML/FormFu/**Model/DBIC.pm#has_many_and_**
>> many_to_many_relationships<http://search.cpan.org/%7Epshangov/HTML-FormF=
u-Model-DBIC-0.09002/lib/HTML/FormFu/Model/DBIC.pm#has_many_and_many_to_man=
y_relationships>
>> >
>>
>> |
>> |
>> but that example schema set does not have the "|many-to-many ||join|
>> |table between books & authors"| as in the tutorial.
>> https://metacpan.org/module/**Catalyst::Manual::Tutorial::**
>> 03_MoreCatalystBasics#CREATE-**A-SQLITE-DATABASE<https://metacpan.org/mo=
dule/Catalyst::Manual::Tutorial::03_MoreCatalystBasics#CREATE-A-SQLITE-DATA=
BASE>
>>
>> I can't figure out how to write the YAML to get FormFu to put the data
>> into my edit form while using the many to many join table. Can anyone
>> help out?
>>
>>
> Hi!
>
> I think, this isn't possible via model::dbic.
> 'To select / deselect rows from a many_to_many relationship, you must use
> a multi-valued element, such as a Checkboxgroup or a Select with multiple
> set.' - http://search.cpan.org/~**pshangov/HTML-FormFu-Model-**
> DBIC-0.09002/lib/HTML/FormFu/**Model/DBIC.pm#many_to_many_**selection<htt=
p://search.cpan.org/%7Epshangov/HTML-FormFu-Model-DBIC-0.09002/lib/HTML/For=
mFu/Model/DBIC.pm#many_to_many_selection>
> .
> If you need a complex dbic operation, try to manipulate the form
> configuration via Catalyst controller. Here is an example (sorry, I copied
> form my app, not a general example, don't care about my variables and
> object)
>
> In the controller:
>
> sub modify : Chained( 'base' ) : PathPart( 'modify' ) : Args( 0 ) : Form {
>    my ( $self, $c ) =3D @_;
> ...
>
>        $c->stash->{form}->load_**config_file('picture/modify.**conf');
>        $position =3D $c->stash->{form}->get_all_**element( { type =3D>
> 'File', id =3D> 'add' } );
>
>        @pictures =3D $c->model('SqlFS')->list_**images( {
>                container =3D> $c->session->{container},
>                id        =3D> $c->session->{itemId} } );
>
>        foreach my $current (@pictures) {
>            $src =3D $c->uri_for( '/api/html/geticon/' .
> $c->session->{container} . '/' . $c->session->{itemId} . '/' .
> $current->name );
>            $position->parent->insert_**before(
>                $position->parent->element( {
>                        name           =3D> $current->name,
>                        type           =3D> 'Image',
>                        src            =3D> $src,
>                        value          =3D> $current->name,
>                        retain_default =3D> 1,
>                        force_default  =3D> 0,
>                    }
>                ),
>                $position
>            );
>        }
>        $c->stash->{form}->process;
> ...
>
>
> And the config:
>
> <elements>
>    type                        Block
>    <attributes>
>        id                      fieldbox
>        class                   fifty
>    </attributes>
>    <elements>
>        type                    Block
>        tag                     label
>        content_loc             form.config.label.picture.**modify.fieldset
>    </elements>
>    <elements>
>        type                    Fieldset
>        id                      placeholder
>        <attributes>
>            class               placeholder
>        </attributes>
>        <elements>
>            <<include           ../common/element/file.**picture.conf>>
>            id                  add
>        </elements>
>    </elements>
>    <elements>
>        type                    Fieldset
>        id                      buttonholder
>        <attributes>
>            class               buttonholder
>        </attributes>
>        <elements>
>            <<include           ../common/element/submit.back.**conf>>
>            value_loc           form.config.value.picture.**modify.back
>        </elements>
>        <elements>
>            <<include           ../common/element/submit.add.**conf>>
>            value_loc           form.config.value.picture.**modify.add
>        </elements>
>    </elements>
> </elements>
>
> ______________________________**_________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/html-**formfu<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/20120411/fa=
11bc26/attachment-0001.htm


More information about the HTML-FormFu mailing list