[html-formfu] problem with setting options on select element

mohanprasad mohan at thebizmo.com
Fri Mar 13 14:48:41 GMT 2009




Carl Franks wrote:
> 
> 2009/3/13 mohanprasad <mohan at thebizmo.com>:
>>
>> Hello,
>>
>> I am trying to set options for a select element in a form.
>> my code is as follows
>>
>> sub content :Chained('stash_product_name') PathPart('') Args(0)
>> FormMethod('load_form') {
>>    my ($self, $c) = @_;
>>    $c->stash->{'template'} = "restricted/add/sample.tt";
>>    my $cc = $c->user->country || 'US';
>>    # Get Price rules for the country code
>>    my $price_rule =
>> $c->model('Database::PriceRule')->search({country_acronym => $cc,
>> "LOWER(payment_method)" => "creditcard"});
>>    my @price_rules;
>>    while(my $row = $price_rule->next) {
>>        push(@price_rules, [$row->price_structure_id, $row->value]);
>>    }
>>    my $form = HTML::FormFu->new;
>>    $form = $c->stash->{form};
>>    my $price_cat_element = $form->get_element({ type => 'Select', name =>
>> 'price_structure_id'});
>>    $price_cat_element->options(@price_rules);
>> }
>>
>> sub load_form {
>>    my ( $self, $c ) = @_;
>>    return { 'load_config_file' => "restricted/add/sample.yml" };
>> }
>>
>> I am getting the following error.
>> Caught exception in Sample::Controller::Restricted::Add->content "Can't
>> call
>> method "options" on an undefined value at
>> /home/mohan/search/script/../lib/Sample/Controller/Restricted/Add.pm line
>> 184."
>>
>> I tried to print the values that
>> Could you please tell me where i am doing wrong.
> 
> Hi,
> 
> You should be using get_field() - not get_element()
> 
> get_element / get_all_elements are not for common-use.
> 
> Cheers,
> Carl
> 
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
> 
> 

Thanks Carl,  It works after changing it to get_field.

Best Regards,
Mohan

-- 
View this message in context: http://n2.nabble.com/problem-with-setting-options-on-select-element-tp2473689p2473806.html
Sent from the HTML-FormFu mailing list archive at Nabble.com.




More information about the HTML-FormFu mailing list