NAME

Para::Frame::Widget - Common template widgets

DESCRIPTION

Para::Frame::Widget is an optional module. It will not be used unless the application calls it or uses the default application init method.

Widgets can be implemented either as exported objects (functions / methods / variables) or as templates for inclusion or defined template macros.

These are the standard widgets defined as Perl code. See also the standard Para::Frame::Template::Components.

Exported objects

/selectorder
/slider
/jump
/submit
/go
/go_js
/forward
/forward_url
/alfanum_bar
/rowlist
/list2block
/preserve_data
/param_includes
/hidden
/input
/textarea
/filefield
/css_header
/inflect

slider

  slider( %attrs )

Draws a series of radiobuttons representing a range of numerical values.

field = form field name

min = value of the leftmost radiobutton (default is 0)

max = value of the rightmost radiobutton (default is 100)

number = number of buttons (default is 6)

current = The current value. The nearest button will be selected.

The $current value will be taken from query param $field or $current or 0, in turn.

jump

  jump( $label, $template, \%attrs )

  jump( $label, $template_with_query, \%attrs )

  jump( $label, $uri, \%attrs )

Draw a link to $template with text $label and query params %attrs.

Special attrs include

tag_attr

See /tag_extra_from_params

Used instead of deprecated attrs href_target, href_onclick, href_class, href_id and href_style.

tag_image
Used instead of deprecated attrs href_image.
keep_params

If no class is set, the class will be same_place if the link goes to the current page. To be used with CSS for marking the current page in menues.

Default $label = '???'

Default $template = '', witch would be the current template

jump_extra

  jump_extra( $template, \%attr, \%args )

submit

  submit( $label, $setval, \%attrs )

Draw a form submit button with text $label and value $setval.

Default label = 'Continue'

Default setval is to not have a value

Special attrs include

tag_attr

See /tag_extra_from_params

Used instead of deprecated attrs href_target, href_onclick, href_class, href_id and href_style.

TODO: Do html escape of value

go

  go( $label, $template, $run, \%attrs )

Draw a form submit button with text $label. Sets template to $template and runs action $run. %attrs specifies form fields to be set to specified values.

Default $label = '???'

Default $template is previously set next_template

Default $run = 'nop'

All fields set by %attrs must exist in the form. (Maybe as hidden elements)

Special attrs include

tag_attr

See /tag_extra_from_params

Used instead of deprecated attrs href_target, href_onclick, href_class, href_id and href_style.

TODO: Do html escape of value

forward

  forward( $label, $template, %attrs )

Draw a link to $template with text $label and query params %attrs as well as all the query params. Params set in %attrs overide the previous value. Also sets param 'previous' to current template.

Default $label = '???'

Default $template = '' which would be the current template

preserve_data

  preserve_data( @fields )

Preserves most query params EXCEPT those mentioned in @fields. This is done by creating extra hidden fields. This method will thus only work with a form submit.

The special query params 'previous', 'run', 'route' and 'reqnum' are also excepted. And some more...

alfanum_bar

  alfanum_bar( $template, $field )

Draws a alfanumerical bar, each letter being a link to $template with the letter as value for field $field.

rowlist

  rowlist( $text )

Returns a list of values. One entry for each nonempty row in the text.

list2block

  list2block( @values )

This is the inverse of rowlist. Returns a textblock created from a list of values.

list2block and rowlist can be used for transfering list of values between page requests.

sekectorder

param_includes

hidden

  hidden( $field, $value, %attrs )

Inserts a hidden form field with name $field and value $value.

Default $value is query param $field or $value, in turn.

input

  input( $field, $value, %attrs )

Draws a input field widget.

Sets form field name to $field and value to $value.

$value will be taken from query param $field or $value, in turn.

Attributes:

  size: width of input field  (default is undef)

  maxlength: max number of chars (default is size times 3)

  tdlabel: Sets C<label> and separates it with a C<td> tag.

  label: draws a label before the field with the given text

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and input tag

  id: used for label. Defaults to C<$field>

  onchange: used for scripts, NOT html-escaped!

All other attributes are directly added to the input tag, with the value html escaped.

Example:

  Drawing a input field widget with a label
  [% input('location_name', '', label=loc('Location')) %]

password

  password( $field, $value, %attrs )

Draws a password input field widget.

Sets form field name to $field and value to $value.

$value will be taken from query param $field

Attributes:

  size: width of input field  (default is undef)

  maxlength: max number of chars (default is size times 3)

  tdlabel: Sets C<label> and separates it with a C<td> tag.

  label: draws a label before the field with the given text

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and input tag

  id: used for label. Defaults to C<$field>

  onchange: used for scripts, NOT html-escaped!

All other attributes are directly added to the input tag, with the value html escaped.

Example:

  Drawing a password input field widget with a label
  [% password('location_name', '', label=loc('Password')) %]

textarea

  textarea( $field, $value, %attrs )

Draws a textarea with fied name $field and value $value.

$value will be taken from query param $field or $value, in turn.

Attributes:

  cols: width (default is undef)

  rows: hight (default is 20)

  label: draws a label before the field with the given text

  tdlabel: Sets C<label> and separates it with a C<td> tag.

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and input tag

  id: used for label. Defaults to C<$field>

All other attributes are directly added to the input tag, with the value html escaped.

The default wrap attribute is 'virtual'.

htmlarea

  htmlarea( $field, $value, %attrs )

Draws a htmlarea with fied name $field and value $value.

$value will be taken from query param $field or $value, in turn.

Attributes:

  cols: width (default is 60)

  rows: hight (default is 20)

  label: draws a label before the field with the given text

  tdlabel: Sets C<label> and separates it with a C<td> tag.

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and input tag

  id: used for label. Defaults to C<$field>

All other attributes are directly added to the input tag, with the value html escaped.

The default wrap attribute is 'virtual'.

checkbox

  checkbox( $field, $value, $checked, %attrs )

  checkbox( $field, $value, %attrs )

  checkbox( $field, %attrs )

Draws a checkbox with fied name $field and value $value.

$checked will be taken from query param $field or $checked, in turn. Set to true if query param value equals C$value>. Set to false if $checked is either false or 'f'.

Default $value is 1.

Attributes:

  prefix_label: draws a label before the field with the given text

  suffix_label: draws a label after the field with the given text

  label: sets suffix_label

  tdlabel: sets suffix_label followed by a td

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and checkbox tag

  id: used for label. Defaults to C<$field>

All other attributes are directly added to the input tag, with the value html escaped.

radio

  radio( $field, $value, $checked, %attrs )

  radio( $field, $value, %attrs )

Draws a radio button with field name $field and value $value.

$checked will be taken from query param $field or $checked, in turn. Set to false if $checked is either false or 'f'.

Attributes:

  prefix_label: draws a label before the field with the given text

  suffix_label: draws a label after the field with the given text

  label: sets suffix_label

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and checkbox tag

  id: used for label. Mandatory if label is set

All other attributes are directly added to the input tag, with the value html escaped.

filefield

  filefield( $key, %attrs )

Draws a file-field

cols = Width of input-field value = default file upload value

selector

Name "selector" is because "select" is a protected term.

  selector( $field, $current, @data,
           {
            valkey => $valkey,
            tagkey => $tagkey,
            header => $header,
            %attrs,
           } )
  selector( $field, $current, %data, \%attrs )

Draws a dropdown menu from a list of records (from a DB).

First version:

The select field has the name $field. @data is the list of records returned from select_list(). $valkey is the field name holding the values and $tagkey is the field holding the lables used in the dropdown. $current is the current value used for determining which item to select.

If $header is defiend, it's a label first in the list without a value.

Example:

  <p>[% selector( "sender", "",
             select_list("from users"),
             valkey = "user_id", tagkey = "username",
             header = "Choose"
  ) %]

Second version:

%data is a hashref. The select will consist of all the keys and values, sorted on the keys. $current value will be selected. $field is the name of fhe field.

Example:

  <p>[% selector("frequency", "",
  {
  	'1' = "every month",
  	'2' = "every week",
  	'3' = "every day",
  }) %]



  valkey is the key in the hash for the value

  tagkey is the key in the hash for the label

  relkey is the key in the hash for the rel; see usableforms...

  tdlabel: Sets C<label> and separates it with a C<td> tag.

  label: draws a label before the field with the given text

  label_class: Adds a class to the C<label> tag

  separator: adds the unescaped string between label and input tag

  id: used for label. Defaults to C<$field>

Special attrs include

tag_attr

See /tag_extra_from_params

Used instead of deprecated attrs href_class, href_target, href_id, href_onchange and href_style.

label_from_params

Usage: $params->{id} ||= $key; $out .= label_from_params($params);

tag_extra_from_params

Converts the rest of the params to tag-keys.

Example: $extra = tag_extra_from_params({ class => 'nopad', style => 'float: left' });

         --> $extra = ' class="nopad" style="float: left"'

css_header

Deprecated. Use $site->css->header() instead (Para::Frame::CSS/header).

favicon_header

  favicon_header( $url )

Draws a favicon header.

Paths not beginning with / are relative to the site home.

confirm_simple

  confirm_simple()

  confirm_simple( $headline )

  confirm_simple( $headline, $text )

  confirm_simple( $headline, $text, $button_name )

Returns true if the question in the $headline has been confirmed. Use a unique headline if there is any chanse that multiple confirmations will be required in a route of actions.

If no confirmation has been given, creates a confirmation dialog box and displays it by using an incomplete exception and the confirm.tt template.

Default:

  $headline    = 'Are you sure?'
  $text        = ''
  $button_name = 'Yes'

Example:

In an action:

  use Para::Frame::Widget qw( confirm_simple );
  confirm_simple("Remove $obj_name?");
  $obj->remove;

inflect

  inflect( $number, $one, $many )
  inflect( $number, $none, $one, $many )

If called without $none, it will use $many for $none.

Replaces %d with the $number.

Uses $many for negative numbers

example:

  inflect( 1, "no things", "a thing", "%d things")

returns "a thing"

  inflect(0, "a thing", "%d things")

returns "0 things"

pricify

Added as a filter to html burner.

calendar

  calendar( $field, $value, \%args )

supported args are id tdlabel label label_class separator style class maxlength size onUpdate showsTime date

input_image

$args->{'image_url'} || $Para::Frame::CFG->{'images_uploaded_url'} || '/images';

SEE ALSO

Para::Frame, Para::Frame::Template::Components