Embperl
view release on metacpan or search on metacpan
Embperl/Form/Control.pm view on Meta::CPAN
}
else
{
my $auto = $self -> get_validate_auto_rules ($req) ;
if ($auto)
{
@local_rules = ( -key => $self->{name} );
push @local_rules, -name => $self -> label_text ($req) ;
push @local_rules, @{$auto};
}
}
return \@local_rules ;
}
# ---------------------------------------------------------------------------
#
# has_validate_rules - check if there is anything to validate and
# create auto rules
#
sub has_validate_rules
{
my ($self, $req) = @_ ;
if ($self -> {validate})
{
return scalar(@{$self -> {validate}}) ;
}
my $auto = $self -> get_validate_auto_rules ($req) ;
if ($auto)
{
#$self -> {validate} = $auto ;
return scalar(@$auto) ;
}
$self -> {validate} = [] ;
return 0 ;
}
# ---------------------------------------------------------------------------
#
# has_auto_label_size - returns true if label should be auto sized for this control
#
sub has_auto_label_size
{
return 1 ;
}
# ---------------------------------------------------------------------------
#
# get_value - return the current value for the control
# if dataprefix is set, every hash key within dataprefix is tried
#
sub get_value
{
my ($self, $req) = @_ ;
my $fdat = $req -> {docdata} || \%Embperl::fdat ;
my $name = $self -> {srcname} || $self -> {force_name} || $self -> {name} ;
return $fdat -> {$name} ;
my $dataprefix = $self -> {dataprefix} ;
return $fdat -> {$name} if (!$dataprefix) ;
foreach my $prefix (@$dataprefix)
{
my $item = $prefix?$fdat -> {$prefix}{$name}:$fdat -> {$name} ;
return $item if (defined ($item)) ;
}
return ;
}
# ---------------------------------------------------------------------------
#
# get_std_control_attr - return the default attributes for the control
#
# ret string with all standard attribute, already html escaped
#
sub get_std_control_attr
{
my ($self, $req, $id, $type, $addclass) = @_ ;
my $name = $self -> {force_name} || $self -> {name} ;
my $ctrlid = $id || ($req -> {uuid} . '_' . $name) ;
my $class = $self -> {class} ;
my $width = $self -> {width_percent} ;
my $events = $self -> {eventattrs} ;
$type ||= $self -> {type} ;
my $state = $self -> {state} ;
$state =~ s/[^-a-zA-Z0-9_ ]/_/g ;
my $attrs = qq{class="ef-control ef-control-width-$width ef-control-$type ef-control-$type-width-$width $addclass $class $state" id="$ctrlid" $events} ;
return wantarray?($attrs, $ctrlid, $name):$attrs ;
}
# ------------------------------------------------------------------------------------------
#
# get_display_text - returns the text that should be displayed
#
sub get_display_text
{
my ($self, $req, $value) = @_ ;
$value = $self -> get_value ($req) if (!defined ($value)) ;
if (ref $value)
{
if (ref ($value) eq 'ARRAY')
{
return join (' ', map { $_ ne ''?$self -> get_display_text ($req, $_):() } @$value) ;
}
elsif (ref ($value) eq 'HASH')
{
return join (' ', map { $_ ne ''?$self -> get_display_text ($req, $_):() } %$value) ;
}
( run in 2.203 seconds using v1.01-cache-2.11-cpan-600a1bdf6e4 )