allow adding formbuilder fields at specific positions
This commit is contained in:
parent
a3c6a2f288
commit
3a2b28eb76
3 changed files with 57 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -59,8 +59,26 @@ sub addObject {
|
|||
return $object;
|
||||
}
|
||||
|
||||
# Handle re-ordering of objects
|
||||
=head2 addObjectAt ( $object, $position )
|
||||
|
||||
Adds $object to the list of objects at a certain position, pushing all other
|
||||
objects down.
|
||||
|
||||
=head3 $object
|
||||
|
||||
Some object
|
||||
|
||||
=head3 $position
|
||||
|
||||
The numeric index. 0 is the first object.
|
||||
|
||||
=cut
|
||||
|
||||
sub addObjectAt {
|
||||
my ( $self, $object, $position ) = @_;
|
||||
splice @{$self->objects}, $position, 1, $object;
|
||||
return $object;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue