allow adding formbuilder fields at specific positions

This commit is contained in:
Doug Bell 2011-04-11 15:14:03 -05:00
parent a3c6a2f288
commit 3a2b28eb76
3 changed files with 57 additions and 3 deletions

View file

@ -73,6 +73,33 @@ sub addField {
#----------------------------------------------------------------------------
=head2 addFieldAt ( field, position )
Add a field at a given position.
Note: Unlike L<addField>, this method requires a full field object. It will not
create one for you.
=cut
sub addFieldAt {
my ( $self, $field, $position ) = @_;
$self->addObjectAt( $field, $position );
# Rebuild the fields array to fix the ordering
# We can't be sure the position in $self->objects is the same as in $self->fields
$self->fields([]);
for my $obj ( @{$self->objects} ) {
next unless blessed $obj;
# A field isn't allowed to have child objects
if ( !$obj->can('does') || !$obj->does('WebGUI::FormBuilder::Role::HasObjects') ) {
push @{$self->fields}, $obj;
}
}
return $field;
}
#----------------------------------------------------------------------------
=head2 deleteField ( name )
Delete a field by name. Returns the field deleted.