diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-10-22 13:09:06 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-10-30 13:57:36 +0000 |
commit | ad6ffe41688438c1635a205f3e6ebc18ef2d2b60 (patch) | |
tree | d51b4c8d3a95c61fa2110048893132937e7743f9 | |
parent | b949cd43b196719116a8d6e3dbc2c2598458120b (diff) |
[Mobile] Make sure disable message findable by app
The mobile app is looking at the old extra.datatype_description location
rather than the new disable_form location for per-question disabling (it
does look there for all-category disabling). So we need to make sure the
JSON includes the message in the place where it will be looking.
Note if an extra data question has two answers that disable the form and
they have different messaging, the app will only take one of them.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 03623259c..907834b3a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1699,12 +1699,24 @@ sub generate_category_extra_json : Private { my $false = JSON->false; my @fields = map { - { - %$_, - required => ($_->{required} || '') eq "true" ? $true : $false, - variable => ($_->{variable} || '') eq "true" ? $true : $false, - order => int($_->{order} || 0), + my %data = %$_; + + # Mobile app still looks in datatype_description + if (($_->{variable} || '') eq 'true' && @{$_->{values} || []}) { + foreach my $opt (@{$_->{values}}) { + if ($opt->{disable}) { + my $message = $opt->{disable_message} || $_->{datatype_description}; + $data{datatype_description} = $message; + } + } } + + # Remove unneeded + delete $data{$_} for qw(datatype protected variable order disable_form); + delete $data{datatype_description} unless $data{datatype_description}; + + $data{required} = ($_->{required} || '') eq "true" ? $true : $false; + \%data; } @{ $c->stash->{category_extras}->{$c->stash->{category}} }; return \@fields; |