Skip to content

Commit

Permalink
Removed regex error on save draft (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts-ctrlo authored Jun 19, 2024
1 parent eb3b1ad commit 083f2fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4652,7 +4652,7 @@ sub _process_edit
}
}
else {
$failed = !process( sub { $datum->set_value($newv) } ) || $failed;
$failed = !process( sub { $datum->set_value($newv, draft => defined(param draft)) } ) || $failed;
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions lib/GADS/Datum/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extends 'GADS::Datum';
with 'GADS::Role::Presentation::Datum::String';

after set_value => sub {
my ($self, $value) = @_;
my ($self, $value, %options) = @_;
$value = [$value] if ref $value ne 'ARRAY'; # Allow legacy single values as scalar
$value ||= [];
my @values = grep {defined $_} @$value; # Take a copy first
Expand All @@ -48,15 +48,18 @@ after set_value => sub {
}
my $changed = "@text_all" ne "@old_texts";

if (my $regex = $self->column->force_regex)
if(!$options{draft})
{
foreach my $val (@values)
if (my $regex = $self->column->force_regex)
{
my $msg = __x"Invalid value \"{value}\" for {field}", value => $val, field => $self->column->name;
# Empty values are not checked - these should be done in optional value for field
if ($val && $val !~ /^$regex$/i)
foreach my $val (@values)
{
$changed ? error($msg) : warning($msg);
my $msg = __x "Invalid value \"{value}\" for {field}", value => $val, field => $self->column->name;
# Empty values are not checked - these should be done in optional value for field
if ($val && $val !~ /^$regex$/i)
{
$changed ? error($msg) : warning($msg);
}
}
}
}
Expand Down Expand Up @@ -157,4 +160,3 @@ sub _build_for_code
}

1;

0 comments on commit 083f2fd

Please sign in to comment.