On Tuesday 25 September 2007 13:23:40 Zbigniew Lukasiak wrote: > On 9/24/07, Mario Minati <[EMAIL PROTECTED]> wrote: > > I don't think setup is the right place to do this work. > > When you look at what is happening when creating an element with perl not > > YAML like in 04basic.t: > > The element is created with a call to 'element' (defined in ObjectUtil, > > around line 623). > > This functions calls '_single_element' (defined in ObjectUtil, around > > line 721). > > This function calls '_require_element' (defined in ObjectUtil, around > > line 74). > > And here the 'setup' method of the element is invoked. > > It works fine as long you create your element with all data in place like > > with YAML, but it will fail when doing the chained creation like in the > > mentioned testfile 04basic.t. > > Hmm - thanks - now I think I am getting what is the relation between > the yaml config and object creators in FormFu. > > How about adding just one function: > > sub options_from { > my ( $self, $args ) = @_; > my $stash = $self->form->{stash}; > my $schema = $stash->{'schema'}; > my $resultset_name = $args->{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( $args->{where}, > $args->{search_attr} ); > my $value_field = $args->{value_field} || 'id'; > my $presentation = $args->{presentation} || 'id'; > my @options = map { [ $_->$value_field, $_->$presentation ] } $rs->all; > $self->options( [EMAIL PROTECTED] ); > } > > That would consume a config like: > --- > elements: > - type: Select::DBIC > name: user > options_from: > resultset_name: User > search_attr: > order_by: > - id > > This is as simple as before - but there is one problem - it cannot use > 'name' (to set 'resultset_name') - since it looks like that even if > name is before 'options_from' in the config it is not yet set when > 'options_from' is called. > > And when you don't use the config you would have to call > 'options_from' manually - just like you would call 'options'.
Yes this is a possible solution for the problem. I like my self the chained way bettter as that is the philosophie of formfu. but in my DBIC::Select it also doesn't work for 'where' and 'search_attrs'. For Catalyst I just thought of the idea to set a flag in the config file that prohibits the automatic execution of process during form creation, so that I can attach a callback (which will be an anonymous sub, created with all the necessary data). Anyway this way your module will work also for programatic creation. Greets, Mario _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu