NAME

HTML::Widget::Element - Element Base Class

SYNOPSIS

my $e = $widget->element( $type, $name );
$e->attributes->{class} = 'foo';
$e->name('bar');
$e->class('foo');

DESCRIPTION

Element Base Class.

METHODS

new

attributes

attrs

Arguments: \%attributes

Return Value: \%attributes

The recommended way of setting attributes is to assign directly to a hash-ref key, rather than passing an entire hash-ref, which would overwrite any existing attributes.

# recommended - preserves existing key/value's
$e->attributes->{key} = $value;

# NOT recommended - deletes existing key/value's
$e->attributes( { key => $value } );

However, when a value is set in this recommended way, the object is not returned, so cannot be used for further chained method calls.

$w->element( 'Textfield', 'foo' )
    ->size( 10 )
    ->attributes->{'disabled'} = 'disabled';
# we cannot chain any further method calls after this

Therefore, to set multiple attributes, it is recommended you store the appropriate object, and call "attributes" multiple times.

my $e = $w->element( 'Textfield', 'foo' )->size( 10 );

$e->attributes->{'disabled'} = 'disabled';
$e->attributes->{'id'}       = 'login';

"attrs" is an alias for "attributes".

container

Arguments: \%attributes

Return Value: $container

Creates a new $container_class. Defaults to HTML::Widget::Container.

id

Arguments: $widget

Return Value: $id

Creates a element id.

init

Arguments: $widget

Called once when process() gets called for the first time.

mk_error

Arguments: $widget, \@errors

Return Value: $error

Creates a new HTML::Widget::Error.

mk_input

Arguments: $widget, \%attributes, \@errors

Return Value: $input_tag

Creates a new input tag.

mk_tag

Arguments: $widget, $tagtype, \%attributes, \@errors

Return Value: $element_tag

Creates a new tag.

mk_label

Arguments: $widget, $name, $comment, \@errors

Return Value: $label_tag

Creates a new label tag.

name

Arguments: $name

Return Value: $name

Contains the element name.

passive

Arguments: $bool

Return Value: $bool

Defines if element gets automatically rendered.

prepare

Arguments: $widget

Called whenever $widget->process() gets called, before $element->process().

process

Arguments: \%params, \@uploads

Return Value: \@errors

Called whenever $widget->process()

Returns an arrayref of HTML::Widget::Error objects.

containerize

Arguments: $widget, $value, \@errors

Return Value: $container_tag

Containerize the element, label and error for later rendering. Uses HTML::Widget::Container by default, but this can be over-ridden on a class or instance basis via container_class.

container_class

Arguments: $class

Return Value: $class

Contains the class to use for contain the element which then get rendered. Defaults to HTML::Widget::Container. container_class can be set at a class or instance level:

HTML::Widget::Element->container_class('My::Container'); 
# Override default to custom class

HTML::Widget::Element::Password->container_class(undef); 
# Passwords use the default class
 
$w->element('Textfield')->name('foo')->container_class->('My::Other::Container'); 
# This element only will use My::Other::Container to render

find_elements

Return Value: \@elements

For non-block-container elements, simply returns a one-element list containing this element.

AUTHOR

Sebastian Riedel, sri@oook.de

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.