Figuring this out was somewhat painful, so I thought I would blog it.
I want to use the same form yaml for several different actions (update, create, view) andI had a list of field names I wanted to remove that were not relevant for create.
The remove_element method only works on the immediate children of the invoking object (as does get element), so $form->remove_element does not usually work. I found a posting on the HTML::FormFu list where Carl Franks showed the idiom $element->parent->remove_element($element);
So my code became:
I want to use the same form yaml for several different actions (update, create, view) andI had a list of field names I wanted to remove that were not relevant for create.
The remove_element method only works on the immediate children of the invoking object (as does get element), so $form->remove_element does not usually work. I found a posting on the HTML::FormFu list where Carl Franks showed the idiom $element->parent->remove_element($element);
So my code became:
# remove fields not needed for this action
for (qw(created_by created_time changed_by changed_time version)) {
my $element = $form->get_all_element({name => $_});
if ($element) {
$element->parent->remove_element($element);
}
}
Works great!

Leave a comment