From 9ba260cfb2ce1258be8da7f1ae90a67b8b4be4fa Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Tue, 2 Jun 2026 15:44:43 +0100 Subject: [PATCH] TD-7343 Added auto focus to the check box --- .../CompetencyAssessments.cs | 3 +++ .../AddCompetenciesViewFormData.cs | 5 +---- .../AddCompetenciesViewModel.cs | 2 +- .../AddCompetencies.cshtml | 19 ++++++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs index b353490b19..5c57c433fe 100644 --- a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs +++ b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs @@ -579,6 +579,9 @@ public IActionResult AddComptencies(AddCompetenciesFormData model, int competenc competency.CompetencyFlags = competencyFlags.Where(f => f.CompetencyId == competency.CompetencyID); } var models = new AddCompetenciesViewModel(competencyAssessmentBase, groupedCompetencies, ungroupedCompetencies, frameworkId, framework.FrameworkName, model.SelectedCompetencyIds); + ModelState.Clear(); + ModelState.AddModelError("SelectedCompetencyIds", $"You must select at least one {models.VocabularySingular}"); + ViewBag.RequiredCheckboxMessage = "You must select at least one "+ models.VocabularySingular; return View("AddCompetencies", models); } if (model.SelectedCompetencyIds != null) diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewFormData.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewFormData.cs index 07516407bf..0e6d2ed887 100644 --- a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewFormData.cs +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewFormData.cs @@ -1,11 +1,8 @@ -using System.ComponentModel.DataAnnotations; - -namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments { public class AddCompetenciesFormData { public int ID { get; set; } - [Required(ErrorMessage = "Select at least one competency")] public int[] SelectedCompetencyIds { get; set; } public int FrameworkId { get; set; } } diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewModel.cs index 24433fe494..c1699ef52a 100644 --- a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewModel.cs +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/AddCompetenciesViewModel.cs @@ -28,7 +28,7 @@ public AddCompetenciesViewModel(CompetencyAssessmentBase competencyAssessmentBas public string VocabularyPlural { get; set; } public IEnumerable GroupedCompetencies { get; set; } public IEnumerable UngroupedCompetencies { get; set; } - [Required(ErrorMessage = "Select at least one competency")] + [Required] public int[] SelectedCompetencyIds { get; set; } public int FrameworkId { get; set; } public string? FrameworkName { get; set; } diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/AddCompetencies.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/AddCompetencies.cshtml index 30a10c2ef8..89cea71d72 100644 --- a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/AddCompetencies.cshtml +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/AddCompetencies.cshtml @@ -4,6 +4,8 @@ ViewData["Title"] = $"Add {@Model.VocabularyPlural.ToLower()} to self-assessment"; ViewData["Application"] = "Framework service"; var errorHasOccurred = !ViewData.ModelState.IsValid; + var noSelection = Model.SelectedCompetencyIds == null || !Model.SelectedCompetencyIds.Any(); + var isFirst = true; } @section NavMenuItems { @@ -40,6 +42,11 @@ Add @Model.VocabularyPlural.ToLower() to assessment +
+ + @ViewBag.RequiredCheckboxMessage + +
@if (Model.GroupedCompetencies.Count() > 0) { @foreach (var competencyGroup in Model.GroupedCompetencies) @@ -62,8 +69,18 @@
@foreach (var competency in competencyGroup.FrameworkCompetencies) { + var shouldAutofocus = noSelection && isFirst; + isFirst = false;
- +