Skip to content

Commit

Permalink
detect empty values in required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
oetiker committed Oct 18, 2023
1 parent 48522b2 commit 4ea0067
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/CallBackery/GuiPlugin/AbstractForm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ sub validateData {
if (not ref $entry){
die mkerror(4095,trm("sorry, don't know the field you are talking about"));
}
return if not $entry->{set}{required} and (not defined $formData->{$fieldName} or length($formData->{$fieldName}) == 0);
my $fieldIsEmpty = (not defined $formData->{$fieldName} or length($formData->{$fieldName}) == 0);
return if not $entry->{set}{required} and $fieldIsEmpty;
if ($entry->{validator}){
my $start = time;
my $data = $entry->{validator}->($formData->{$fieldName},$fieldName,$formData);
$self->log->debug(sprintf("validator %s: %0.2fs",$fieldName,time-$start));
return $data;
}
# if there is no validator but the field is required, complain
# if the content is empty
elsif ($entry->{set}{required} and $fieldIsEmpty){
return trm('The %1 field is required',$fieldName);
}
return;
}

Expand Down

0 comments on commit 4ea0067

Please sign in to comment.