MT#8627 Add empty destination check into callforward forms

ipeshinskaya/InvoiceTemplate6
Irina Peshinskaya 11 years ago
parent ee06b92b53
commit 51e7c5fb93

@ -109,7 +109,6 @@ has_field 'destination.rm' => (
# },
);
has_field 'destination_add' => (
type => 'AddElement',
repeatable => 'destination',
@ -136,6 +135,24 @@ has_block 'actions' => (
render_list => [qw(save)],
);
sub validate_destination{
my ( $self, $field ) = @_;
my $value = $field->value || [];
my $result = 1;
if( $#$value < 0 ){
$field->add_error($field->label . " is empty");
$result = 0;
}else{
foreach my $destination($field->fields()){
(my($uri_field)) = grep {'destination' eq $_->name} $destination->field('uri')->fields;
if('uri' eq $destination->field('destination')->value && !$uri_field->value){
$uri_field->add_error($uri_field->label . " is empty");
$result = 0;
}
}
}
return $result;
}
1;
# vim: set tabstop=4 expandtab:

@ -105,21 +105,20 @@ has_block 'actions' => (
);
sub validate_active_callforward{
my ( $self, $field ) = @_;
my $value = $field->value || [];
my $result = 1;
my $value = $field->value || [];
if( $#$value < 0 ){
$field->add_error($field->label . ' is empty.');
$result = 0;
}else{
foreach my $map (@$value){
if(! defined $map->{destination_set}){
foreach my $callforward_spec($field->fields()){
my $destination_set_field = $callforward_spec->field('destination_set');
if(!$destination_set_field->value){
$destination_set_field->add_error($destination_set_field->label . ' is empty.');
$result = 0;
last;
}
}
}
if(!$result){
$field->add_error($field->label . " is invalid");
}
return $result;
}
1;

@ -103,7 +103,17 @@ has_block 'fields' => (
render_list => [qw(destination)],
);
has_block 'actions' => (tag => 'div', class => [qw(modal-footer)], render_list => [qw(cf_actions)],);
sub validate_destination{
my ( $self, $field ) = @_;
my $result = 0;
(my($uri_field)) = grep {'destination' eq $_->name} ($field->field('uri')->fields);
if( 'uri' eq $field->field('destination')->value
&& !$uri_field->value ){
$uri_field->add_error($uri_field->label . " is empty");
$result = 0;
}
return $result;
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save