Name HTML::FormWidgets - Create HTML form markup Version 0.6.$Rev: 310 $ Synopsis package CatalystX::Usul::View; use parent qw(Catalyst::View CatalystX::Usul); use HTML::FormWidgets; sub build_widgets { my ($self, $c, $sources, $config) = @_; my $s = $c->stash; my $data = []; $sources ||= []; $config ||= {}; for my $part (map { $s->{ $_ } } grep { $s->{ $_ } } @{ $sources }) { if (ref $part eq q(ARRAY) and $part->[ 0 ]) { push @{ $data }, $_ for (@{ $part }); } else { push @{ $data }, $part } } $config->{assets } = $s->{assets}; $config->{base } = $c->req->base; $config->{content_type} = $s->{content_type}; $config->{fields } = $s->{fields} || {}; $config->{form } = $s->{form}; $config->{hide } = $s->{hidden}->{items}; $config->{messages } = $s->{messages}; $config->{pwidth } = $s->{pwidth}; $config->{root } = $c->config->{root}; $config->{static } = $s->{static}; $config->{swidth } = $s->{width} if ($s->{width}); $config->{template_dir} = $c->config->{template_dir}; HTML::FormWidgets->build( $config, $data ); return $data; } Description Transforms a Perl data structure which defines one or more "widgets" into HTML or XHTML. Each widget is comprised of these optional components: a line or question number, a prompt string, a separator, an input field, additional field help, and Ajax field error string. Input fields are selected by the widget *type* attribute. A factory subclass implements the method that generates the HTML or XHTML for that input field type. Adding more widget types is straightforward This module is using the Javascript library to modify default browser behaviour This module is used by CatalystX::Usul::View and as such its main use is as a form generator within a Catalyst application Subroutines/Methods build $class->build( $config, $data ); The "build" method iterates over a data structure that represents the form. One or more lists of widget definitions are processed in turn. New widgets are created and their rendered output replaces their definitions in the data structure new $widget = $class->new( [{] key1 => value1, ... [}] ); Construct a widget. Mostly this is called by the "build" method. It requires the factory subclass for the widget type. This method takes a large number of options with each widget using only few of them. Each option is described in the factory subclasses which use that option inflate $widget->inflate( $args ); Creates new objects and returns their rendered output. Called by the "_render" methods in the factory subclasses to inflate embeded widget definitions init $widget->init( $args ); Initialises this object with data from the passed arguments. This is usually overridden in the factory subclass which sets the default for it's own attributes and then calls this method in the base class loc localize $message_text = $widget->localize( $message_id, @args ); Use the supplied key to return a value from the *messages* hash. This hash was passed to the constructor and should contain any literal text used by any of the widgets render $html = $widget->render; Assemble the components of the generated widget. Each component is concatenated onto a scalar which is the returned value. This method calls "_render" which should be defined in the factory subclass for this widget type. This method uses these attributes: clear If set to left the widget begins with an "
" element stepno If true it's value is wrapped in a "" element and appended to the return value prompt If true it's value is wrapped in a "