0
|
1 package Form::ValueItem;
|
|
2 use strict;
|
|
3 use base qw(Form::Item);
|
|
4 use Common;
|
|
5 use Form::Filter;
|
|
6
|
|
7 BEGIN {
|
|
8 DeclareProperty Value => ACCESS_ALL;
|
|
9 DeclareProperty Type => ACCESS_READ;
|
|
10 DeclareProperty Schema => ACCESS_READ;
|
|
11 }
|
|
12
|
|
13 sub CTOR {
|
|
14 my ($this,%args) = @_;
|
|
15
|
|
16 $this->SUPER::CTOR(@args{qw(Id Form Parent Attributes)});
|
|
17 $this->{$Type} = $args{'Type'};
|
|
18 $this->{$Schema} = $args{'Schema'} or die new Exception('A field schema is required');
|
|
19 }
|
|
20
|
|
21 sub isEmpty {
|
|
22 my ($this) = @_;
|
|
23
|
|
24 return length $this->{$Value} ? 0 : 1;
|
|
25 }
|
|
26
|
|
27 sub Validate {
|
|
28 my ($this,$rhDisableFilters) = @_;
|
|
29
|
|
30 $rhDisableFilters ||= {};
|
|
31
|
|
32 my @errors;
|
|
33
|
|
34 foreach my $filter (grep {$_->SUPPORTED_CONTEXT & (Form::Filter::CTX_SINGLE) and not exists $rhDisableFilters->{$_}} map {$_->Instance} $this->{$Schema}->Filters) {
|
|
35 my $result = $filter->Invoke($this,Form::Filter::CTX_SINGLE | Form::Filter::CTX_EXISTENT,$this->{$Schema},$this->Parent);
|
|
36 if ($result->State == Form::FilterResult::STATE_SUCCESS_STOP) {
|
|
37 return ();
|
|
38 } elsif ($result->State == Form::FilterResult::STATE_ERROR) {
|
|
39 push @errors,$result;
|
|
40 }
|
|
41 }
|
|
42
|
|
43 return @errors;
|
|
44 }
|
|
45
|
|
46
|
|
47 1;
|