Here is my take on the subject - HTML::FormFu::Element::Select::DBIC.
It overrides setup - seems like this is simpler than both render and
process - but setup is not documented so I don't know if that is the
right way.

Below is the code - very short.  I attach also a package - together
with some tests.

I am also going to extend the fill_formfu_values from
DBIx::Class::HTML::FormFu so that it works with has_many and
many_to_many relations but for that I need first a 'multi' Select
field.

Cheers,
Zbyszek

-------------------------------------------------------------

package HTML::FormFu::Element::Select::DBIC;
use strict;

BEGIN {
    use vars qw($VERSION );
    $VERSION     = '0.01';
}

use base 'HTML::FormFu::Element::Select';
use Carp qw/ croak /;

__PACKAGE__->mk_accessors( qw/
    schema
    resultset_name
    where
    search_attr
    presentation
    value_field
/ );

sub setup {
#sub new {
    my $self = shift;
    $self->next::method(@_);
    my $stash = $self->form->{stash};
    my $schema = $stash->{'schema'};
    my $resultset_name = $self->resultset_name || ucfirst $self->name;
    croak "Needs a DBIx::Class schema and a ResultSet class name"
    if ( ! $schema) & ( ! $resultset_name );
    my $rs = $schema->resultset( $resultset_name )->search( $self->where,
        $self->search_attr );
    my $value_field = $self->value_field || 'id';
    my $presentation = $self->presentation || 'id';
    my @options = map { [ $_->$value_field, $_->$presentation ] } $rs->all;
    $self->options( [EMAIL PROTECTED] );
}

1;


-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/

Attachment: HTML-FormFu-DBIC-0.01.tar.gz
Description: GNU Zip compressed data

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to