diff --git a/NHSUKViewComponents.Web/ViewComponents/DateInputViewComponent.cs b/NHSUKViewComponents.Web/ViewComponents/DateInputViewComponent.cs index 6928110..e10084f 100644 --- a/NHSUKViewComponents.Web/ViewComponents/DateInputViewComponent.cs +++ b/NHSUKViewComponents.Web/ViewComponents/DateInputViewComponent.cs @@ -18,6 +18,7 @@ public class DateInputViewComponent : ViewComponent /// /// Leave blank for no custom css class. /// Leave blank for no hint. + /// Leave blank/false for set label as page body . /// public IViewComponentResult Invoke( string id, @@ -26,7 +27,8 @@ public IViewComponentResult Invoke( string monthId, string yearId, string cssClass, - IEnumerable? hintTextLines + IEnumerable? hintTextLines, + bool? isPageHeading = false ) { var model = ViewData.Model; @@ -59,7 +61,8 @@ public IViewComponentResult Invoke( yearErrors?.Count > 0, nonEmptyErrors, string.IsNullOrEmpty(cssClass) ? null : cssClass, - hintTextLines.Any() ? hintTextLines : null + hintTextLines.Any() ? hintTextLines : null, + isPageHeading ); return View(viewModel); } diff --git a/NHSUKViewComponents.Web/ViewComponents/RadioListViewComponent.cs b/NHSUKViewComponents.Web/ViewComponents/RadioListViewComponent.cs index 2f021f1..401abcc 100644 --- a/NHSUKViewComponents.Web/ViewComponents/RadioListViewComponent.cs +++ b/NHSUKViewComponents.Web/ViewComponents/RadioListViewComponent.cs @@ -16,7 +16,8 @@ public IViewComponentResult Invoke( string hintText, bool required, string? requiredClientSideErrorMessage = default, - string cssClass = default + string cssClass = default, + string? optionalRadio = default ) { var model = ViewData.Model; @@ -24,7 +25,7 @@ public IViewComponentResult Invoke( var errorMessages = ViewData.ModelState[property?.Name]?.Errors.Select(e => e.ErrorMessage) ?? new string[] { }; - var radiosList = radios.Select( + var radiosList = radios.Where(x=>x.Label != optionalRadio).Select( r => new RadiosItemViewModel( r.Value, r.Label, @@ -32,12 +33,16 @@ public IViewComponentResult Invoke( r.HintText ) ); + var viewModel = new RadiosViewModel( aspFor, label, string.IsNullOrEmpty(hintText) ? null : hintText, radiosList, + string.IsNullOrEmpty(optionalRadio) ? null : radios.Where(x => x.Label == optionalRadio) + .Select(r => new RadiosItemViewModel(r.Value, r.Label, IsSelectedRadio(aspFor, r, populateWithCurrentValues), r.HintText)) + .FirstOrDefault(), errorMessages, required, string.IsNullOrEmpty(requiredClientSideErrorMessage) ? null : requiredClientSideErrorMessage, diff --git a/NHSUKViewComponents.Web/ViewModels/DateInputViewModel.cs b/NHSUKViewComponents.Web/ViewModels/DateInputViewModel.cs index 6e6116f..8b1762a 100644 --- a/NHSUKViewComponents.Web/ViewModels/DateInputViewModel.cs +++ b/NHSUKViewComponents.Web/ViewModels/DateInputViewModel.cs @@ -22,7 +22,8 @@ public DateInputViewModel( bool hasYearError, IEnumerable errorMessages, string? cssClass = null, - IEnumerable? hintTextLines = null + IEnumerable? hintTextLines = null, + bool? isPageHeading = false ) { Id = id; @@ -35,6 +36,7 @@ public DateInputViewModel( YearValue = yearValue; CssClass = cssClass; HintTextLines = hintTextLines; + IsPageHeading = isPageHeading; HasDayError = hasDayError; HasMonthError = hasMonthError; HasYearError = hasYearError; @@ -51,6 +53,8 @@ public DateInputViewModel( public string? YearValue { get; set; } public string? CssClass { get; set; } public IEnumerable? HintTextLines { get; set; } + public bool? IsPageHeading { get; set; } + public bool HasError => HasDayError || HasMonthError || HasYearError; public IEnumerable ErrorMessages { get; set; } } diff --git a/NHSUKViewComponents.Web/ViewModels/RadiosViewModel.cs b/NHSUKViewComponents.Web/ViewModels/RadiosViewModel.cs index 2e30914..9932e96 100644 --- a/NHSUKViewComponents.Web/ViewModels/RadiosViewModel.cs +++ b/NHSUKViewComponents.Web/ViewModels/RadiosViewModel.cs @@ -10,6 +10,7 @@ public RadiosViewModel( string label, string hintText, IEnumerable radios, + RadiosItemViewModel optionalRadio, IEnumerable errorMessages, bool required, string? requiredClientSideErrorMessage = default, @@ -21,6 +22,7 @@ public RadiosViewModel( Label = !required && !label.EndsWith("(optional)") ? label + " (optional)" : label; HintText = hintText; Radios = radios; + OptionalRadio = optionalRadio; ErrorMessages = errorMessageList; HasError = errorMessageList.Any(); Required = required; @@ -38,6 +40,7 @@ public RadiosViewModel( public readonly bool HasError; public IEnumerable Radios { get; set; } + public RadiosItemViewModel OptionalRadio { get; set; } public bool Required { get; set; } public string RequiredClientSideErrorMessage { get; set; } } diff --git a/NHSUKViewComponents.Web/Views/Shared/Components/DateInput/Default.cshtml b/NHSUKViewComponents.Web/Views/Shared/Components/DateInput/Default.cshtml index 6010fac..444d561 100644 --- a/NHSUKViewComponents.Web/Views/Shared/Components/DateInput/Default.cshtml +++ b/NHSUKViewComponents.Web/Views/Shared/Components/DateInput/Default.cshtml @@ -10,8 +10,18 @@
- - @Model.Label + + @if(Model.IsPageHeading.GetValueOrDefault()==true) + { +

+ @Model.Label +

+ } + else + { + @Model.Label + } +
@if (Model.HintTextLines != null) { @foreach (var hintText in Model.HintTextLines) { diff --git a/NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml b/NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml index 00f3e6d..ddce262 100644 --- a/NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml +++ b/NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml @@ -2,6 +2,10 @@ @using NHSUKViewComponents.Web.ViewModels @model RadiosViewModel +@{ + int counter = 0; + +}
@@ -40,6 +44,7 @@
@foreach (var (radio, index) in Model.Radios.Select((r, i) => (r, i))) { + counter = index; var radioId = $"{radio.Value}-{index}"; if (!string.IsNullOrWhiteSpace(Model.Class)) { @@ -91,6 +96,31 @@ } } + @if(Model.OptionalRadio != null) + { +
or
+ var radioId = $"{Model.OptionalRadio.Value}-{++counter}"; +
+ + + @if (Model.OptionalRadio.HintText != null) + { +
+ @Model.OptionalRadio.HintText +
+ } +
+ }