HTML::Widget(3pm)
πΈ HTML::Widget(3pm) πΈ
okay bestie, welcome to the manual for HTML::Widget(3pm) β it's the HTML Widget And Validation Framework. It's giving iconic Perl energy. π
β¨ NAME β¨
HTML::Widget β HTML Widget And Validation Framework
π NOTE π
real talk bestie: HTML::Widget is no longer under active development and the current maintainers are instead pursuing an intended replacement (see the mailing-list for details). π
Volunteer maintainers / developers for HTML::Widget, please contact the mailing-list. π«Ά
β¨ SYNOPSIS β¨
here's the whole vibe in code form:
use HTML::Widget;
# Create a widget
my $w = HTML::Widget->new('widget')->method('get')->action('/');
# Add a fieldset to contain the elements
my $fs = $w->element( 'Fieldset', 'user' )->legend('User Details');
# Add some elements
$fs->element( 'Textfield', 'age' )->label('Age')->size(3);
$fs->element( 'Textfield', 'name' )->label('Name')->size(60);
$fs->element( 'Submit', 'ok' )->value('OK');
# Add some constraints
$w->constraint( 'Integer', 'age' )->message('No integer.');
$w->constraint( 'Not_Integer', 'name' )->message('Integer.');
$w->constraint( 'All', 'age', 'name' )->message('Missing value.');
# Add some filters
$w->filter('Whitespace');
# Process
my $result = $w->process;
my $result = $w->process($query);
# Check validation results
my @valid_fields = $result->valid;
my $is_valid = $result->valid('foo');
my @invalid_fields = $result->have_errors;
my $is_invalid = $result->has_errors('foo');;
# CGI.pm-compatible! (read-only)
my $value = $result->param('foo');
my @params = $result->param;
# Catalyst::Request-compatible
my $value = $result->params->{foo};
my @params = keys %{ $result->params };
# Merge widgets (constraints and elements will be appended)
$widget->merge($other_widget);
# Embed widgets (as fieldset)
$widget->embed($other_widget);
# Get list of elements
my @elements = $widget->get_elements;
# Get list of constraints
my @constraints = $widget->get_constraints;
# Get list of filters
my @filters = $widget->get_filters;
# Complete xml result
[% result %]
[% result.as_xml %]
# Iterate over elements
<form action="/foo" method="get">
[% FOREACH element = result.elements %]
[% element.field_xml %]
[% element.error_xml %]
[% END %]
</form>
# Iterate over validation errors
[% FOREACH element = result.have_errors %]
<p>
[% element %]:<br/>
<ul>
[% FOREACH error = result.errors(element) %]
<li>
[% error.name %]: [% error.message %] ([% error.type %])
</li>
[% END %]
</ul>
</p>
[% END %]
<p><ul>
[% FOREACH element = result.have_errors %]
[% IF result.error( element, 'Integer' ) %]
<li>[% element %] has to be an integer.</li>
[% END %]
[% END %]
</ul></p>
[% FOREACH error = result.errors %]
<li>[% error.name %]: [% error.message %] ([% error.type %])</li>
[% END %]
# XML output looks like this (easy to theme with css)
<form action="/foo/bar" id="widget" method="post">
<fieldset>
<label for="widget_age" id="widget_age_label"
class="labels_with_errors">
Age
<span class="label_comments" id="widget_age_comment">
(Required)
</span>
<span class="fields_with_errors">
<input id="widget_age" name="age" size="3" type="text"
value="24" class="Textfield" />
</span>
</label>
<span class="error_messages" id="widget_age_errors">
<span class="Regex_errors" id="widget_age_error_Regex">
Contains digit characters.
</span>
</span>
<label for="widget_name" id="widget_name_label">
Name
<input id="widget_name" name="name" size="60" type="text"
value="sri" class="Textfield" />
<span class="error_messages" id="widget_name_errors"></span>
</label>
<input id="widget_ok" name="ok" type="submit" value="OK" />
</fieldset>
</form>
π DESCRIPTION π
Create easy to maintain HTML widgets! π
Everything is optional, use validation only or just generate forms, you can embed and merge them later. no cap.
The API was designed similar to other popular modules like Data::FormValidator and FormValidator::Simple, HTML::FillInForm is also built in (and much faster).
This Module is very powerful, don't misuse it as a template system! π€ periodt.
π METHODS π
π new π
Arguments: $name, \%attributes
Return Value: $widget
Create a new HTML::Widget object. The name parameter will be used as the id of the form created by the to_xml method.
The "attributes" argument is equivalent to using the "attributes" method.
π action π
Arguments: $uri
Return Value: $uri
Get/Set the action associated with the form. The default is no action, which causes most browsers to submit to the current URI.
π attributes π
π attrs π
Arguments: %attributes
Arguments: \%attributes
Return Value: $widget
Arguments: none
Return Value: \%attributes
Accepts either a list of key/value pairs, or a hash-ref.
$w->attributes( $key => $value );
$w->attributes( { $key => $value } );
Returns the $widget object, to allow method chaining.
As of v1.10, passing a hash-ref no longer deletes current attributes, instead the attributes are added to the current attributes hash.
This means the attributes hash-ref can no longer be emptied using "$w->attributes( { } );". Instead, you may use "%{ $w->attributes } = ();".
As a special case, if no arguments are passed, the return value is a hash-ref of attributes instead of the object reference. This provides backwards compatibility to support:
$w->attributes->{key} = $value;
"attrs" is an alias for "attributes".
π¦ container π¦
Arguments: $tag
Return Value: $tag
Get/Set the tag used to contain the XML output when as_xml is called on the HTML::Widget object. Defaults to "form".
πΈ element_container_class πΈ
Arguments: $class_name
Return Value: $class_name
Get/Set the container_class override for all elements in this widget. If set to non-zero value, process will call $element->container_class($class_name) for each element. Defaults to not set.
See "container_class" in HTML::Widget::Element.
π§ elem π§
π§ element π§
Arguments: $type, $name, \%attributes
Return Value: $element
Add a new element to the Widget. Each element must be given at least a type. The name is used to generate an id attribute on the tag created for the element, and for form-specific elements is used as the name attribute. The returned element object can be used to set further attributes, please see the individual element classes for the methods specific to each one.
The "attributes" argument is equivalent to using the attributes method.
If the element starts with a name other than "HTML::Widget::Element::", you can fully qualify the name by using a unary plus:
$self->element( "+Fully::Qualified::Name", $name );
The type can be one of the following:
π§© HTML::Widget::Element::Block π§©
my $e = $widget->element('Block');
Add a Block element, which by default will be rendered as a "DIV".
my $e = $widget->element('Block');
$e->type('img');
π HTML::Widget::Element::Button π
my $e = $widget->element( 'Button', 'foo' );
$e->value('bar');
Add a button element.
my $e = $widget->element( 'Button', 'foo' );
$e->value('bar');
$e->content('<b>arbitrary markup</b>');
$e->type('submit');
Add a button element which uses a "button" html tag rather than an "input" tag. The value of "content" is not html-escaped, so may contain html markup.
βοΈ HTML::Widget::Element::Checkbox βοΈ
my $e = $widget->element( 'Checkbox', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->checked('checked');
$e->value('bar');
Add a standard checkbox element.
π·οΈ HTML::Widget::Element::Fieldset π·οΈ
my $e = $widget->element( 'Fieldset', 'foo' );
$e->legend('Personal details');
$e->element('Textfield', 'name');
$e->element('Textarea', 'address');
Adds a nested fieldset element, which can contain further elements.
π«₯ HTML::Widget::Element::Hidden π«₯
my $e = $widget->element( 'Hidden', 'foo' );
$e->value('bar');
Add a hidden field. This field is mainly used for passing previously gathered data between multiple page forms.
π HTML::Widget::Element::Password π
my $e = $widget->element( 'Password', 'foo' );
$e->comment('(Required)');
$e->fill(1);
$e->label('Foo');
$e->size(23);
$e->value('bar');
Add a password field. This is a text field that will not show the user what they are typing, but show asterisks instead.
π» HTML::Widget::Element::Radio π»
my $e = $widget->element( 'Radio', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->checked('checked');
$e->value('bar');
Add a radio button to a group. Radio buttons with the same name will work as a group. That is, only one item in the group will be "on" at a time.
ποΈ HTML::Widget::Element::RadioGroup ποΈ
my $e = $widget->element( 'RadioGroup', 'name' );
$e->comment('(Required)');
$e->label('Foo'); # Label for whole radio group
$e->value('bar'); # Currently selected value
$e->labels([qw/Fu Bur Garch/]); # default to ucfirst of values
This is a shortcut to add multiple radio buttons with the same name at the same time. See above.
π HTML::Widget::Element::Reset π
$e = $widget->element( 'Reset', 'foo' );
$e->value('bar');
Create a reset button. The text on the button will default to "Reset", unless you call the value() method. This button resets the form to its original values.
π HTML::Widget::Element::Select π
my $e = $widget->element( 'Select', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->size(23);
$e->options( foo => 'Foo', bar => 'Bar' );
$e->selected(qw/foo bar/);
...it's giving "pick your fighter" but as a <select>, bestie. π
You're creating a dropdown or a multi-select list element with a bunch of options. The options come in as a key => value list β the keys are the actual selected IDs, and the values are the strings that get displayed in the dropdown. No cap.
HTML::Widget::Element::Span
my $e = $widget->element( 'Span' );
$e->content('bar');
Making a cute little span tag holding whatever content you hand it. β¨
Heads up bestie: spans cannot be constrained because they're not entry fields. They're just vibes, not input. π«Ά
The content can be a string, an HTML::Element object, or an array-ref of HTML::Element objects.
HTML::Widget::Element::Submit
$e = $widget->element( 'Submit', 'foo' );
$e->value('bar');
Making a submit button, iconic behavior. The text on the button defaults to "Submit" unless you call the value() method and change it up. π
$e = $widget->element( 'Submit', 'foo' );
$e->value('bar');
$e->src('image.png');
$e->width(100);
$e->height(35);
And this one? An image submit button. The button gets displayed as an image, using the file at url "src". Main character energy, literally a picture. πΌοΈ
HTML::Widget::Element::Textarea
my $e = $widget->element( 'Textarea', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->cols(30);
$e->rows(40);
$e->value('bar');
$e->wrap('wrap');
A textarea field β it's the multi-line input field for text. Long-form thoughts only. π
HTML::Widget::Element::Textfield
my $e = $widget->element( 'Textfield', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->size(23);
$e->maxlength(42);
$e->value('bar');
A single line text field. Short and sweet, one line, periodt.
HTML::Widget::Element::Upload
my $e = $widget->element( 'Upload', 'foo' );
$e->comment('(Required)');
$e->label('Foo');
$e->accept('text/html');
$e->maxlength(1000);
$e->size(23);
A field for uploading files. It'll probably be rendered as a textfield, with a button for choosing a file. π
Lowkey magic: adding an Upload element automatically calls $widget->enctype('multipart/form-data') for you. You don't have to do it yourself, it just happens. Slay.
id
name
- Arguments:
$name - Return Value:
$name
Get or set the widget id. π
And name? It's an alias for id. Same thing, different nickname, iykyk.
get_elements
- Arguments:
%options - Return Value:
@elements
my @elements = $self->get_elements;
my @elements = $self->get_elements( type => 'Textfield' );
my @elements = $self->get_elements( name => 'username' );
Returns a list of all the elements you've added to the widget. The whole roster. π
- If a
'type'argument is given, it only returns the elements of that type. - If a
'name'argument is given, it only returns the elements with that name.
get_elements_ref
- Arguments:
%options - Return Value:
\@elements
Takes the exact same arguments as get_elements, but returns an arrayref of results instead of a list. Same tea, different cup. π
get_element
- Arguments:
%options - Return Value:
$element
my $element = $self->get_element;
my $element = $self->get_element( type => 'Textfield' );
my $element = $self->get_element( name => 'username' );
Basically get_elements(), except it only returns the first element in the list. Just the one. The chosen one. β
Accepts the same arguments as get_elements().
find_elements
- Arguments:
%options - Return Value:
@elements
Similar to get_elements, and accepts the same arguments, but it does a recursive search through block-level elements. It's digging deeper, fr fr. π
const
constraint
- Arguments:
$type,@field_names - Return Value:
$constraint
Set up a constraint on one or more elements. When process() is called on the Widget object with a $query object, the parameters of the query get checked against the constraints you specified. The HTML::Widget::Constraint object is returned so you can set further attributes on it. π§
The string 'Not_' can be prepended to each type name to negate the effects. So checking for a non-integer becomes 'Not_Integer'. Cute little reverse uno. π
If the constraint package name starts with something other than HTML::Widget::Constraint::, you can fully qualify the name by using a unary plus:
$self->constraint( "+Fully::Qualified::Name", @names );
Important: constraint checking is done after all HTML::Widget::Filter have been applied. Order matters, bestie.
@names should contain a list of element names that the constraint applies to. The type of constraint can be one of:
HTML::Widget::Constraint::All
my $c = $widget->constraint( 'All', 'foo', 'bar' );
The fields passed to the "All" constraint are those which are required fields in the form. No skipping. π«
HTML::Widget::Constraint::AllOrNone
my $c = $widget->constraint( 'AllOrNone', 'foo', 'bar' );
If any of the fields passed to the "AllOrNone" constraint are filled in, then they all must be filled in. It's all or nothing, literally the name. π
HTML::Widget::Constraint::Any
my $c = $widget->constraint( 'Any', 'foo', 'bar' );
At least one or more of the fields passed to this constraint must be filled. Just one, we're not greedy. π
HTML::Widget::Constraint::ASCII
my $c = $widget->constraint( 'ASCII', 'foo' );
The fields passed to this constraint get checked to make sure their contents contain ASCII characters.
HTML::Widget::Constraint::Bool
my $c = $widget->constraint( 'Bool', 'foo' );
The fields passed to this constraint get checked to make sure their contents contain a 1 or 0.
HTML::Widget::Constraint::Callback
my $c = $widget->constraint( 'Callback', 'foo' )->callback(sub {
my $value=shift;
return 1;
});
This constraint lets you provide your own callback sub for validation. The callback sub is called once for each submitted value of each named field. So yeah, it's called a lot. π―
HTML::Widget::Constraint::CallbackOnce
my $c = $widget->constraint( 'CallbackOnce', 'foo' )->callback(sub {
my $value=shift;
return 1;
});
This constraint also lets you provide your own callback sub for validation. The callback sub is called once per call of process. One and done. β¨
HTML::Widget::Constraint::Date
my $c = $widget->constraint( 'Date', 'year', 'month', 'day' );
This constraint ensures that the three fields passed in are a valid date. π
HTML::Widget::Constraint::DateTime
my $c =
$widget->constraint( 'DateTime', 'year', 'month', 'day', 'hour',
'minute', 'second' );
This constraint ensures that the six fields passed in are a valid date and time. π°οΈ
HTML::Widget::Constraint::DependOn
my $c =
$widget->constraint( 'DependOn', 'foo', 'bar' );
If the first field listed is filled in, all of the others are required. Codependency but make it form validation. π«Ά
HTML::Widget::Constraint::Email
my $c = $widget->constraint( 'Email', 'foo' );
Check that the field given contains a valid email address, according to RFC 2822, using the Email::Valid module. π§
HTML::Widget::Constraint::Equal
my $c = $widget->constraint( 'Equal', 'foo', 'bar' );
$c->render_errors( 'foo' );
The fields passed to this constraint must contain the same information, or be empty. Twins fr. π―
HTML::Widget::Constraint::HTTP
my $c = $widget->constraint( 'HTTP', 'foo' );
This constraint checks that the field(s) passed in are valid URLs. The regex used to test this can be set manually using the ->regex method. π
HTML::Widget::Constraint::In
my $c = $widget->constraint( 'In', 'foo' );
$c->in( 'possible', 'values' );
Check that a value is one of a specified set. Pick from the list only, bestie. π
HTML::Widget::Constraint::Integer
my $c = $widget->constraint( 'Integer', 'foo' );
Check that the field contents are an integer. π’
HTML::Widget::Constraint::Length
my $c = $widget->constraint( 'Length', 'foo' );
$c->min(23);
$c->max(50);
Ensure that the contents of the field are at least $min long, and no longer than $max. π
HTML::Widget::Constraint::Number
my $c = $widget->constraint( 'Number', 'foo' );
Ensure that the content of the field is a number.
HTML::Widget::Constraint::Printable
my $c = $widget->constraint( 'Printable', 'foo' );
The contents of the given field must only be printable characters. The regex used to test this can be set manually using the ->regex method. π¨οΈ
HTML::Widget::Constraint::Range
my $c = $widget->constraint( 'Range', 'foo' );
$c->min(23);
$c->max(30);
The contents of the field must be numerically within the given range. Stay in your lane, numerically. π
HTML::Widget::Constraint::Regex
my $c = $widget->constraint( 'Regex', 'foo' );
$c->regex(qr/^\w+$/);
Tests the contents of the given field(s) against a user supplied regex. You bring the pattern, it brings the test. π§ͺ
HTML::Widget::Constraint::String
my $c = $widget->constraint( 'String', 'foo' );
The field must only contain characters in \w. i.e. [a-zaZ0-9_]
HTML::Widget::Constraint::Time
my $c = $widget->constraint( 'Time', 'hour', 'minute', 'second' );
The three fields passed to this constraint must constitute a valid time. β°
constraint_all
constrain_all
- Arguments:
@constraint_types - Return Value:
@constraints
$w->element( Textfield => 'name' );
$w->element( Textfield => 'password' );
$w->constraint_all( 'All' );
For each named type, add a constraint to all elements currently defined. Bulk apply, obsessed. π₯
It does not add a constraint for elements which return false for"allow_constraint" in HTML::Widget::Elementβ that includesHTML::Widget::Element::Spanand any element that inherits fromHTML::Widget::Element::Block. So those get skipped, no exceptions.
get_constraints
- Arguments:
%options - Return Value:
@constraints
my @constraints = $self->get_constraints;
my @constraints = $self->get_constraints( type => 'Integer' );
Returns a list of all constraints added to the widget. ποΈ
If a 'type' argument is given, it only returns the constraints of that type.
get_constraints_ref
- Arguments:
%options - Return Value:
\@constraints
Accepts the same arguments as get_constraints, but returns an arrayref of results instead of a list. π
get_constraint
- Arguments:
%options - Return Value:
$constraint
my $constraint = $self->get_constraint;
my $constraint = $self->get_constraint( type => 'Integer' );
Similar to get_constraints, but only returns the first constraint in the list. β
Accepts the same arguments as get_constraints.
embed
- Arguments:
@widgets - Arguments:
$element,@widgets
okay so this one is the part where you take another whole widget object and smoosh its contents into this one π Every embedded object shows up as another set of fields (wrapped up in a fieldset tag), sitting pretty inside the form that gets created. And bestie, listen closely: no copy is made of the widgets you're embedding, which means calling as_xml on the resulting object will change data in the widget objects. it's giving shared-reference realness π
If you hand it an element argument, the widgets get embedded into that element instead. And there are no checks on whether the element you passed actually belongs to $self β it just trusts you. main character energy, honestly.
β οΈ Heads up! Without an element argument, embed embeds into the top level of the widget, and NOT into any subcontainer (whether you created it or it got created implicitly). If that's not the vibe you need, pick one of these:
# while building $self:
$in_here = $self->element('Fieldset', 'my_fieldset');
# later:
$self->embed($in_here, @widgets);
# these are equivalent:
$self->embed(($self->find_elements)[0], @widgets);
$self->embed_into_first(@widgets); # but this is faster!
And if you're just building a widget and do not need to import constraints and filters from some other widget? Do not use embed at all, bestie π«Ά just assemble it using the methods provided by HTML::Widget::Element::Fieldset. periodt.
β¨ embed_into_first
Arguments: @widgets
Literally the same deal as embed, except it embeds into the first subcontainer (fieldset) instead of into the top level form. that's it. that's the whole thing πΈ
β¨ empty_errors
Arguments: $bool
Return Value: $bool
After validation, if errors are found, a span tag gets created with the id "fields_with_errors". Set this value to cause that span tag to always be generated, no matter what. π
β¨ enctype
Arguments: $enctype
Return Value: $enctype
Set/Get the encoding type of the form. It can be either "application/x-www-form-urlencoded" β which is the default β or "multipart/form-data". Peep the spec over at http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4 if you're feeling academic π
And plot twist: if the widget contains an Upload element, the enctype is automatically set to 'multipart/form-data'. slay, it handles itself.
β¨ explicit_ids
Argument: $bool
Return Value: $bool
When true, elements, fieldsets and blocks will not be given DOM ids, unless you explicitly set them with attributes. like:
$w->element( 'Textfield', 'foo', {id => 'my_id'} )
The form itself will always be given an "id", which is "widget" by default. can't strip that one, sorry π
β¨ filter
Arguments: $type, @field_names
Return Value: $filter
Add a filter. Just like constraints, filters can be applied to one or more elements. These actually change the contents of the fields that the user supplied, before the constraints get checked. So it only makes sense to apply filters to fields that can contain text β Password, Textfield, Textarea, Upload. anything else is just a vibe waste π¦
If the filter starts with a name other than "HTML::Widget::Filter::", you can fully qualify the name by using a unary plus:
$self->filter( "+Fully::Qualified::Name", @names );
There are currently two types of filter:
π HTML::Widget::Filter::Callback
my $f = $widget->filter( 'Callback', 'foo' );
$f->callback( \&my_callback );
Filter given field(s) using a user-defined subroutine. you're the callback now, bestie.
π HTML::Widget::Filter::HTMLEscape
my $f = $widget->filter( 'HTMLEscape', 'foo' );
Escapes HTML entities in the given field(s). bye bye sneaky markup π
π HTML::Widget::Filter::HTMLStrip
my $f = $widget->filter( 'HTMLStrip', 'foo' );
Strips HTML tags from the given field(s).
my $f = $widget->filter( 'HTMLStrip', 'foo' );
$f->allow( 'p', 'br' );
Specify a list of HTML tags which shouldn't be stripped. so p and br get to stay, iconic of them.
π HTML::Widget::Filter::LowerCase
my $f = $widget->filter( 'LowerCase', 'foo' );
Make given field(s) all lowercase. quiet, shy, lowercase. π
π HTML::Widget::Filter::TrimEdges
my $f = $widget->filter( 'TrimEdges', 'foo' );
Removes whitespace from the beginning and end of the given field(s). βοΈ
π HTML::Widget::Filter::UpperCase
my $f = $widget->filter( 'UpperCase', 'foo' );
Make given field(s) all uppercase. LOUD. π£
π HTML::Widget::Filter::Whitespace
my $f = $widget->filter( 'Whitespace', 'foo' );
Removes all whitespace from the given field(s). every last crumb π
β¨ filter_all
Arguments: @filter_types
Return Value: @filters
$w->element( Textfield => 'name' );
$w->element( Textfield => 'age' );
$w->filter_all( 'Whitespace' );
For each named type, add a filter to all elements currently defined. one filter, every element, efficiency queen π
It does not add a filter for elements which return false for HTML::Widget::Element/allow_filter β and that includes HTML::Widget::Element::Span and any element that inherits from HTML::Widget::Element::Block.
β¨ get_filters
Arguments: %options
Return Value: @filters
my @filters = $self->get_filters;
my @filters = $self->get_filters( type => 'Integer' );
Returns a list of all filters added to the widget. π
If a 'type' argument is given, it only returns the filters of that type. filter your filters, iykyk.
β¨ get_filters_ref
Arguments: %options
Return Value: \@filters
Accepts the same arguments as get_filters, but returns an arrayref of results instead of a list. same energy, different wrapper π
β¨ get_filter
Arguments: %options
Return Value: $filter
my @filters = $self->get_filter;
my @filters = $self->get_filter( type => 'Integer' );
Similar to get_filters, but only returns the first filter in the list. just the one. the headliner. β
Accepts the same arguments as get_filters.
β¨ indi / indicator
Arguments: $field_name
Return Value: $field_name
Set/Get a boolean field. It's a convenience method for you, the user, so you can keep track of which of your many Widget objects were submitted. It's also used by Catalyst::Plugin::HTML::Widget. little bookkeeping buddy π«Ά
β¨ legend
Arguments: $legend
Return Value: $legend
Set/Get a legend for this widget. This tag is used to label the fieldset. cute little caption moment π
β¨ merge
Arguments: @widgets
Arguments: $element, @widgets
Merge elements, constraints and filters from other widgets into this one. The elements get added to the end of the list of elements that have already been set. no cutting the line π«
Without an element argument, and with standard widgets, the contents of the first top-level element of each widget will be merged into the first top-level element of this widget. This emulates the previous behaviour.
With an element argument, the widgets are merged into the named element. And again β no checks are made on whether the provided element belongs to $self. it's trusting like that π
β¨ method
Arguments: $method
Return Value: $method
Set/Get the method used to submit the form. Can be set to either "post" or "get". The default is "post". classic.
β¨ result / process
Arguments: $query, \@uploads
Return Value: $result
Once you've finished setting up the widget and all its elements, call this to create an HTML::Widget::Result. If you pass it a $query, it will run filters and validation on the parameters. Then you can use that Result object to produce the HTML. the grand finale β¨
"result" is an alias for "process". twins. π
β¨ query
Arguments: $query
Return Value: $query
Set/Get the query object to use for validation input. You can also just pass the query object straight to the process method directly, if that's more your vibe.
β¨ strict
Arguments: $bool
Return Value: $bool
Only consider parameters that pass at least one constraint valid. strict queen behavior. π
β¨ subcontainer
Arguments: $tag
Return Value: $tag
Set/Get the subcontainer tag to use. Defaults to "fieldset". π
β¨ uploads
Arguments: \@uploads
Return Value: \@uploads
Contains an arrayref of Apache2::Upload compatible objects. file uploads said hi π
β¨ xhtml_strict
Arguments: $bool
Return Value: $bool
When "true", it is an error to have any element at the top-level of the widget which is not derived from HTML::Widget::Element::Block. Currently, the only valid element supplied is the HTML::Widget::Element::Fieldset. π
When "true", the top-level widget may not have a L/legend>.
π¦ Frequently Asked Questions (FAQ)
How do I add an onSubmit handler to my form?
$widget->attributes( onsubmit => $javascript );
See "attributes" in HTML::Widget. easy. πΈ
How do I add an onChange handler to my form field?
$element->attributes( onchange => $javascript );
See "attributes" in HTML::Widget::Element.
Element X does not have an accessor for Y!
You can add any arbitrary attributes with "attributes" in HTML::Widget::Element. no accessor? no problem. π
How can I add a tag which isn't included?
You can either create your own element module files and use them as you would a standard element, or alternatively...
You can call type on an HTML::Widget::Element::Block element to change the rendered tag.
$w->element('Block')->type('br');
# will render as
<br />
How can I render some elements in a HTML list?
my $ul = $w->element('Block')->type('ul');
$ul->element('Block')->type('li')
->element( Textfield => foo' );
$ul->element('Block')->type('li')
->element( Textfield => 'bar' );
# will render as
<ul>
<li>
<input class="textfield" id="widget_foo" name="foo" type="text" />
</li>
<li>
<input class="textfield" id="widget_bar" name="bar" type="text" />
</li>
</ul>
π SUPPORT
Mailing list:
http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
come hang out, we're nice π«Ά
π SUBVERSION REPOSITORY
The publicly viewable subversion code repository is at http://dev.catalyst.perl.org/repos/Catalyst/trunk/HTML-Widget/. go peek, bestie π
π SEE ALSO
Catalyst Catalyst::Plugin::HTML::Widget HTML::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.
and that's the whole page, bestie!! πβ¨ this gem lives in perl v5.36.0, dated 2023-08-10, and it's filed under HTML::Widget(3pm). now go build something iconic with it ππ¦
π¦ where this page comes from
- debian trixie: libhtml-widget-perl 1.11-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-widget-perl 1.11-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-widget-perl 1.11-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-widget-perl 1.11-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms