[html-formfu] FormFu many_to_many YAML declaration

Gabor HALASZ halasz.g at freemail.hu
Wed Apr 11 20:15:56 GMT 2012


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-FormFu-Model-DBIC-0.09002/lib/HTML/FormFu/Model/DBIC.pm#has_many_and_many_to_many_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
>
> 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.
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 ) = @_;
...

         $c->stash->{form}->load_config_file('picture/modify.conf');
         $position = $c->stash->{form}->get_all_element( { type => 
'File', id => 'add' } );

         @pictures = $c->model('SqlFS')->list_images( {
                 container => $c->session->{container},
                 id        => $c->session->{itemId} } );

         foreach my $current (@pictures) {
             $src = $c->uri_for( '/api/html/geticon/' . 
$c->session->{container} . '/' . $c->session->{itemId} . '/' . 
$current->name );
             $position->parent->insert_before(
                 $position->parent->element( {
                         name           => $current->name,
                         type           => 'Image',
                         src            => $src,
                         value          => $current->name,
                         retain_default => 1,
                         force_default  => 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>



More information about the HTML-FormFu mailing list