[html-formfu] position element not found error when using insert_before

mohanprasad mohan at thebizmo.com
Thu Oct 15 12:29:14 GMT 2009


Hi Carl,
Thanks for your reply.
I updated the things as you suggested.
Even after that it was giving me the same error.
Now its my mistake, actually the yml form data i provided in my previous
message is wrapped by another yml form.
that yml form data is as follows.
action: /add/track/data
auto_fieldset: 1
auto_id: '%f_%n'
id: add_track
load_config_file: __path_to(root,forms)__/track_info.yml
elements:
- type: Fieldset
  add_attributes:
    class: butt
  elements:
  - type: Submit
    name: submit
    value_loc: Save Track

So i changed the auto_fieldset : 0 , then it worked fine.

When i had a look at generated html codes in both cases, an empty fieldset
is created in the case with auto_fieldset: 1, which is not the case when
auto_fieldset: 0,
As i was doing $form->get_element; its giving me the first fieldset which is
empty, as a result formfu cant find position element not found.
Thanks for your help.

Best Regards,
Mohan


Carl Franks wrote:
> 
> 2009/10/15 mohanprasad <mohan at thebizmo.com>:
>>
>> Hi,
>>
>> I am trying to insert a new element in my catalyst controller action
>> using
>> below code.
>> i have two hidden fileds, one text box, i am trying to insert the new
>> element before hidden fields.
>>
>> my $form = $self->form;
>> my $file = "restricted/add/product";
>> $form->load_config_filestem($file);
>> $form->process;
>> $c->stash->{form} = $form;
>> my $new_element = $form->element( { type => 'Block', tag => 'label',
>> content
>> => 'file upload error' } );
>> my $pos = $form->get_element({ type => 'Hidden', name => 'media_id'});
>> my $hidden_fields = $form->hidden_fields;
>> $c->log->debug("hidden fields = $hidden_fields");
>> $form->insert_before($new_element, $pos);
> 
> Hi,
> 
> Because all the fields are attached to a Fieldset - not directly to the
> form,
> you'll find $pos is undef.
> Because of this, you also need to call insert_before() on the
> fieldset, not the form.
> Also, you'll find that if you're creating $new_element on the same
> form, you'll end up with 2 copies of it after insert_before(), so you
> should probably be using another form object to create it.
> 
> You need to do something like this:
> 
> my $fieldset = $form->get_element;
> my $pos = $fieldset->get_element( 'media_id' );
> 
> my $new_element = $different_form_object->element( \%args );
> 
> $fieldset->insert_before( $new_element, $pos );
> 
> Cheers,
> Carl
> 
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
> 
> 

-- 
View this message in context: http://n2.nabble.com/position-element-not-found-error-when-using-insert-before-tp3827638p3828984.html
Sent from the HTML-FormFu mailing list archive at Nabble.com.



More information about the HTML-FormFu mailing list