display — display HTML form element
Attribute | Pos. | Req. | Default | Description |
---|---|---|---|---|
table | yes | |||
column | yes | |||
key | yes | |||
type | widget | |||
template | ||||
override | ||||
value | ||||
default | ||||
already_got_data | ||||
ui_no_meta_display | ||||
meta | ||||
meta_table | ||||
view | ||||
arbitrary | ||||
specific | ||||
label | ||||
default_widget | ||||
restrict_allow | ||||
name | name of form element | |||
restrict_deny | ||||
cols | ||||
rows | ||||
return_hash | ||||
applylocale | ||||
meta_url | ||||
interpolate | 0 | interpolate output? | ||
hide | 0 | Hide the tag return value? |
Example: Dropdown menus with country names
Display country dropdown menus looked up from the country
table,
using empty value for billing as default.
[display name="country" table="country" lookup=code field=name type="select" value="[value country]"] [display name="b_country" table="country" lookup=code field=name type="select" value="[value b_country]" options="=-- Please select --"]
Interchange 5.9.0:
Source: code/UI_Tag/display.coretag
Lines: 21
# Copyright 2002-2007 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # # $Id: display.coretag,v 1.14 2007-03-30 23:40:54 pajamian Exp $ UserTag display Order table column key UserTag display attrAlias base table UserTag display attrAlias database db UserTag display attrAlias col column UserTag display attrAlias row key UserTag display attrAlias code key UserTag display addAttr 1 UserTag display Interpolate 1 UserTag display posNumber 3 Require Module Vend::Table::Editor UserTag display Version $Revision: 1.14 $ UserTag display MapRoutine Vend::Table::Editor::display
Source: lib/Vend/Table/Editor.pm
Lines: 1075
sub display { my ($table,$column,$key,$opt) = @_; if( ref($opt) ne 'HASH' ) { $opt = get_option_hash($opt); } my $template = $opt->{type} eq 'hidden' ? '' : $opt->{template}; if($opt->{override}) { $opt->{value} = defined $opt->{default} ? $opt->{default} : ''; } if(! defined $opt->{value} and $table and $column and length($key)) { $opt->{value} = tag_data($table, $column, $key); $opt->{already_got_data} = 1; } my $mtab; my $record; my $no_meta = $opt->{ui_no_meta_display}; METALOOK: { ## No meta display wanted last METALOOK if $no_meta; ## No meta display possible $table and $column or $opt->{meta} or last METALOOK; ## We get a metarecord directly, though why it would be here ## and not in options I don't know if($opt->{meta} and ref($opt->{meta}) eq 'HASH') { $record = $opt->{meta}; last METALOOK; } $mtab = $opt->{meta_table} || $::Variable->{UI_META_TABLE} || 'mv_metadata' or last METALOOK; my $meta = Vend::Data::database_exists_ref($mtab) or do { ::logError("non-existent meta table: %s", $mtab); undef $mtab; last METALOOK; }; my $view = $opt->{view} || $opt->{arbitrary}; ## This is intended to trigger on the first access if($table eq $mtab and $column eq $meta->config('KEY')) { if($view and $opt->{value} !~ /::.+::/) { $base_entry_value = ($opt->{value} =~ /^([^:]+)::(\w+)$/) ? $1 : $opt->{value}; } else { $base_entry_value = $opt->{value} =~ /(\w+)::/ ? $1 : $opt->{value}; } } my (@tries) = "${table}::$column"; unshift @tries, "${table}::${column}::$key" if length($key) and $opt->{specific}; my $sess = $Vend::Session->{mv_metadata} || {}; push @tries, { type => $opt->{type} } if $opt->{type} || $opt->{label}; for my $metakey (@tries) { ## In case we were passed a meta record last if $record = $sess->{$metakey} and ref $record; $record = meta_record($metakey, $view, $meta) and last; } } my $w; METAMAKE: { last METAMAKE if $no_meta; if( ! $record ) { $record = { %$opt }; } else { ## Here we allow override with the display tag, even with views and ## extended my @override = qw/ append attribute db callback_prescript callback_postscript class default extra disabled field form form_name filter height help help_url id label js_check lookup lookup_exclude lookup_query maxlength name options outboard passed pre_filter prepend table type type_empty width /; for(@override) { delete $record->{$_} if ! length($record->{$_}); next unless defined $opt->{$_}; $record->{$_} = $opt->{$_}; } } if($record->{type_empty} and length($opt->{value}) == 0) { $record->{type} = $record->{type_empty}; } else { $record->{type} ||= $opt->{default_widget}; } $record->{name} ||= $column; #::logDebug("record now=" . ::uneval($record)); if($record->{options} and $record->{options} =~ /^[\w:,]+$/) { #::logDebug("checking options"); PASS: { my $passed = $record->{options}; if($passed eq 'tables') { my @tables = $Tag->list_databases(); $record->{passed} = join (',', "=--none--", @tables); } elsif($passed =~ /^(?:filters|\s*codedef:+(\w+)(:+(\w+))?\s*)$/i) { my $tag = $1 || 'filters'; my $mod = $3; $record->{passed} = Vend::Util::codedef_options($tag, $mod); } elsif($passed =~ /^columns(::(\w*))?\s*$/) { my $total = $1; my $tname = $2 || $record->{db} || $table; if ($total eq '::' and $base_entry_value) { $tname = $base_entry_value; } $record->{passed} = join ",", "=--none--", $Tag->db_columns($tname), ; } elsif($passed =~ /^keys(::(\w+))?\s*$/) { my $tname = $2 || $record->{db} || $table; $record->{passed} = join ",", "=--none--", $Tag->list_keys($tname), ; } } } #::logDebug("checking for custom widget"); if ($record->{type} =~ s/^custom\s+//s) { my $wid = lc $record->{type}; $wid =~ tr/-/_/; $record->{attribute} ||= $column; $record->{table} ||= $mtab; $record->{rows} ||= $record->{height}; $record->{cols} ||= $record->{width}; $record->{field} ||= 'options'; $record->{name} ||= $column; eval { $w = $Tag->$wid($record->{name}, $opt->{value}, $record, $opt); }; if($@) { ::logError("error using custom widget %s: %s", $wid, $@); } last METAMAKE; } $opt->{restrict_allow} ||= $record->{restrict_allow}; #::logDebug("formatting prepend/append/lookup_query name=$opt->{name} restrict_allow=$opt->{restrict_allow}"); for(qw/append prepend lookup_query/) { next unless $record->{$_}; if($opt->{restrict_allow}) { $record->{$_} = $Tag->restrict({ log => 'none', enable => $opt->{restrict_allow}, disable => $opt->{restrict_deny}, body => $record->{$_}, }); } else { $record->{$_} = expand_values($record->{$_}); } $record->{$_} = Vend::Util::resolve_links($record->{$_}); $record->{$_} =~ s/_UI_VALUE_/$opt->{value}/g; $record->{$_} =~ /_UI_URL_VALUE_/ and do { my $tmp = $opt->{value}; $tmp =~ s/(\W)/sprintf '%%%02x', ord($1)/eg; $record->{$_} =~ s/_UI_URL_VALUE_/$tmp/g; }; $record->{$_} =~ s/_UI_TABLE_/$table/g; $record->{$_} =~ s/_UI_COLUMN_/$column/g; $record->{$_} =~ s/_UI_KEY_/$key/g; } if($opt->{opts}) { my $r = get_option_hash(delete $opt->{opts}); for my $k (keys %$r) { $record->{$k} = $r->{$k}; } } #::logDebug("overriding defaults"); #::logDebug("passed=$record->{passed}") if $record->{debug}; my %things = ( attribute => $column, cols => $opt->{cols} || $record->{width}, passed => $record->{options}, rows => $opt->{rows} || $record->{height}, value => $opt->{value}, applylocale => $opt->{applylocale}, ); while( my ($k, $v) = each %things) { next if length $record->{$k}; next unless defined $v; $record->{$k} = $v; } #::logDebug("calling Vend::Form with record=" . ::uneval($record)); if($record->{save_defaults}) { my $sd = $Vend::Session->{meta_defaults} ||= {}; $sd = $sd->{"${table}::$column"} ||= {}; while (my ($k,$v) = each %$record) { next if ref($v) eq 'CODE'; $sd->{$k} = $v; } } $w = Vend::Form::display($record); if($record->{filter}) { $w .= qq{<input type="hidden" name="ui_filter:$record->{name}" value="}; $w .= $record->{filter}; $w .= '">'; } } if(! defined $w) { my $text = $opt->{value}; my $iname = $opt->{name} || $column; # Count lines for textarea my $count; $count = $text =~ s/(\r\n|\r|\n)/$1/g; HTML::Entities::encode($text, $ESCAPE_CHARS::std); my $size; if ($count) { $count++; $count = 20 if $count > 20; $w = <<EOF; <textarea name="$iname" cols="60" rows="$count">$text</textarea> EOF } elsif ($text =~ /^\d+$/) { my $cur = length($text); $size = $cur > 8 ? $cur + 1 : 8; } else { $size = 60; } $w = <<EOF; <input name="$iname" size="$size" value="$text"> EOF } my $array_return = wantarray; #::logDebug("widget=$w"); # don't output label if widget is hidden form variable only # and not an array type undef $template if $w =~ /^\s*<input\s[^>]*type\s*=\W*hidden\b[^>]*>\s*$/i; return $w unless $template || $opt->{return_hash} || $array_return; if($template and $template !~ /\s/) { $template = <<EOF; <tr> <td> <b>\$LABEL\$</b> </td> <td valign="top"> <table cellspacing="0" cellmargin="0"><tr><td>\$WIDGET\$</td><td>\$HELP\${HELP_URL} \ <br$Vend::Xtrailer><a href="\$HELP_URL\$">help</a>{/HELP_URL}</td></tr></table> </td> </tr> EOF } $record->{label} ||= $column; my %sub = ( WIDGET => $w, HELP => $opt->{applylocale} ? errmsg($record->{help}) : $record->{help}, META_URL => $opt->{meta_url}, HELP_URL => $record->{help_url}, LABEL => $opt->{applylocale} ? errmsg($record->{label}) : $record->{label}, ); #::logDebug("passed meta_url=$opt->{meta_url}"); $sub{HELP_EITHER} = $sub{HELP} || $sub{HELP_URL}; if($opt->{return_hash}) { $sub{OPT} = $opt; $sub{RECORD} = $record; return \%sub; } elsif($array_return) { return ($w, $sub{LABEL}, $sub{HELP}, $record->{help_url}); } else { # Strip the {TAG} {/TAG} pairs if nothing there $template =~ s#{([A-Z_]+)}(.*?){/\1}#$sub{$1} ? $2: '' #ges; # Insert the TAG $sub{HELP_URL} ||= 'javascript:void(0)'; $template =~ s/\$([A-Z_]+)\$/$sub{$1}/g; #::logDebug("substituted template is: $template"); return $template; } }