Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DP-544 - Exclusions form bug fixes #711

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CO.CDP.OrganisationApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;

namespace CO.CDP.OrganisationApp.Pages.Forms;

Expand Down Expand Up @@ -46,18 +47,33 @@ public override void SetAnswer(FormAnswer? answer)
{
case nameof(FormAnswer.OptionValue):
value = answer?.OptionValue;

if (value != null && Options?.Choices != null && Options.Choices.ContainsKey(value))
{
SelectedOption = value;
}

break;
case nameof(FormAnswer.JsonValue):
value = answer?.JsonValue;

if (value != null && Options?.Choices != null)
{
// We have to deserialize and serialize the json before checking equality,
// because the representation straight out of postgres does not match the representation from C# with respect to whitespace
Dictionary<string, object>? parsedValue = JsonSerializer.Deserialize<Dictionary<string, object>>(value);
string reseralizedValue = JsonSerializer.Serialize(parsedValue);

if (Options.Choices.ContainsKey(reseralizedValue))
{
SelectedOption = reseralizedValue;
}
}

break;
default:
throw new InvalidOperationException($"Unsupported field: {Options?.ChoiceAnswerFieldName}");
}

if (value != null && Options?.Choices != null && Options.Choices.ContainsKey(value))
{
SelectedOption = value;
}
}

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="declarationStatement" name="CheckBoxInput" type="checkbox" value="true" @(Model.CheckBoxInput == true ? "checked" : "")>
<label class="govuk-label govuk-checkboxes__label" for="declarationStatement">
@Html.Raw(Model.Options?.Choices?.FirstOrDefault())
@Html.Raw(Model.Options?.Choices?.Values.FirstOrDefault())
</label>
</div>
</div>
Expand Down