[Html-widget] Setting field values using query parameters

Andreas Marienborg omega at palle.net
Fri Oct 13 19:15:33 CEST 2006


Most of the time I use DBIx::Class::HTMLWidget, and the way I present  
defaults is to include them in a "mockobject" on form creation.

so usually, from cat, I do something like this structure:


sub create : Local {
     my ($self, $c) = @_;
     my $local_company = $c->req->param('local_company');

     $c->stash->{object} = $c->model('Search::Person')->new 
({local_company => $local_company || undef });

     $c->forward('edit');
}
sub edit : Local {
     my ( $self, $c, $id) = @_;
     my $object = $c->stash->{object};
     unless ($object) {
         $object = $c->model('Search::Person')->find($id);
         $c->stash->{object} = $object;
     }

     die "no person" unless $object;

	# Create form
     $object->fill_widget($c->widget('edit_person'));
}


In that way I can set any field on the object I create via new, as to  
make sure it doesnt end up in the Db before its complete.


Dunno if that helps you, but if nothing else works, you can look at  
the HTMLWidget sources fill_widget method for inspiration perhaps :)


andreas



On 13. okt. 2006, at 18.17, Will Hawes wrote:

> When a user initially visits a form (i.e. prior to submission), I'd  
> like
> to be able to set field values using query parameters. For example my
> user might click a link such as
> "http://www.domain.com/view_form?field1=value", with field "field1"
> displaying "value" as a result.
>
> As far as I can see the only way to do this at present is to call
> $widget->process( $request ), but that validates all the elements. I
> don't want any validation until the form has been submitted. At this
> point all I want to do is set some field values. I think what I'm  
> after
> is something along the lines of
>
> sub fill {
>    my( $self, $values ) = @_;
>    for my $e ( $self->find_elements ) {
>      my $name = $e->name;
>      my $value = $values->{$name};
>      $e->value($value)
>        if( defined $value && $e->can('value') );
>    }
> }
>
> No provision in the hacked up example for checkboxes etc but hopefully
> you get the idea.
>
> I'd be slightly surprised if something like this doesn't already  
> exist -
> have I missed it?
>
> _______________________________________________
> Html-widget mailing list
> Html-widget at lists.rawmode.org
> http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget




More information about the Html-widget mailing list