Skip to content

Commit 826e320

Browse files
authored
[AA-1798] - Adds maxlength attribute on Educator and School screens - Includes Sc… (#534)
* Adds maxlength attribute on Educator and School screens - Includes Schools as well * Fix
1 parent 7151ed4 commit 826e320

File tree

8 files changed

+136
-29
lines changed

8 files changed

+136
-29
lines changed

Application/EdFi.Ods.AdminApp.Web/Models/ViewModels/EducationOrganizations/AddPsiSchoolModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using EdFi.Ods.AdminApp.Management.Api.Models;
8+
using FluentValidation;
89

910
namespace EdFi.Ods.AdminApp.Web.Models.ViewModels.EducationOrganizations
1011
{
@@ -19,5 +20,33 @@ public class AddPsiSchoolModel: AddSchoolModel
1920

2021
public class AddPsiSchoolModelValidator : AddSchoolModelValidatorBase<AddPsiSchoolModel>
2122
{
23+
public AddPsiSchoolModelValidator()
24+
{
25+
RuleFor(m => m.Name).NotEmpty();
26+
RuleFor(m => m.Name)
27+
.MaximumLength(75)
28+
.WithMessage("The School Name would be too long for Admin App. The maximum length is 75 characters.")
29+
.When(x => x.Name != null);
30+
31+
RuleFor(m => m.StreetNumberName).NotEmpty();
32+
RuleFor(m => m.StreetNumberName)
33+
.MaximumLength(150)
34+
.WithMessage("The Address would be too long for Admin App. The maximum length is 150 characters.")
35+
.When(x => x.StreetNumberName != null);
36+
37+
RuleFor(m => m.State).NotEmpty();
38+
39+
RuleFor(m => m.City).NotEmpty();
40+
RuleFor(m => m.City)
41+
.MaximumLength(30)
42+
.WithMessage("The City would be too long for Admin App. The maximum length is 30 characters.")
43+
.When(x => x.City != null);
44+
45+
RuleFor(m => m.ZipCode).NotEmpty();
46+
RuleFor(m => m.ZipCode)
47+
.MaximumLength(17)
48+
.WithMessage("The Zip Code would be too long for Admin App. The maximum length is 17 characters.")
49+
.When(x => x.ZipCode != null);
50+
}
2251
}
2352
}

Application/EdFi.Ods.AdminApp.Web/Models/ViewModels/EducationOrganizations/AddSchoolModel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,33 @@ public abstract class AddSchoolModelValidatorBase<T> : AbstractValidator<T> wher
4040
protected AddSchoolModelValidatorBase()
4141
{
4242
RuleFor(x => x.SchoolId).NotEmpty();
43-
RuleFor(x => x.Name).NotEmpty();
44-
RuleFor(x => x.StreetNumberName).NotEmpty();
45-
RuleFor(x => x.City).NotEmpty();
43+
44+
RuleFor(m => m.Name).NotEmpty();
45+
RuleFor(m => m.Name)
46+
.MaximumLength(75)
47+
.WithMessage("The School Name would be too long for Admin App. The maximum length is 75 characters.")
48+
.When(x => x.Name != null);
49+
50+
RuleFor(m => m.StreetNumberName).NotEmpty();
51+
RuleFor(m => m.StreetNumberName)
52+
.MaximumLength(150)
53+
.WithMessage("The Address would be too long for Admin App. The maximum length is 150 characters.")
54+
.When(x => x.StreetNumberName != null);
55+
4656
RuleFor(x => x.State).NotEmpty();
47-
RuleFor(x => x.ZipCode).NotEmpty();
57+
58+
RuleFor(m => m.City).NotEmpty();
59+
RuleFor(m => m.City)
60+
.MaximumLength(30)
61+
.WithMessage("The City would be too long for Admin App. The maximum length is 30 characters.")
62+
.When(x => x.City != null);
63+
64+
RuleFor(m => m.ZipCode).NotEmpty();
65+
RuleFor(m => m.ZipCode)
66+
.MaximumLength(17)
67+
.WithMessage("The Zip Code would be too long for Admin App. The maximum length is 17 characters.")
68+
.When(x => x.ZipCode != null);
69+
4870
RuleFor(x => x.GradeLevels).Must(x => x != null && x.Count > 0).WithMessage("You must choose at least one grade level");
4971
}
5072
}

Application/EdFi.Ods.AdminApp.Web/Models/ViewModels/EducationOrganizations/EditPsiSchoolModel.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using EdFi.Ods.AdminApp.Management.Api.Models;
8+
using FluentValidation;
89

910
namespace EdFi.Ods.AdminApp.Web.Models.ViewModels.EducationOrganizations
1011
{
@@ -18,5 +19,39 @@ public class EditPsiSchoolModel: EditSchoolModel
1819
}
1920

2021
public class EditPsiSchoolModelValidator : EditSchoolModelValidatorBase<EditPsiSchoolModel>
21-
{ }
22+
{
23+
public EditPsiSchoolModelValidator()
24+
{
25+
RuleFor(m => m.PostSecondaryInstitutionId).NotEmpty();
26+
RuleFor(m => m.Name).NotEmpty();
27+
RuleFor(m => m.Name)
28+
.MaximumLength(75)
29+
.WithMessage("The School Name would be too long for Admin App. The maximum length is 75 characters.")
30+
.When(x => x.Name != null);
31+
32+
RuleFor(m => m.StreetNumberName).NotEmpty();
33+
RuleFor(m => m.StreetNumberName)
34+
.MaximumLength(150)
35+
.WithMessage("The Address would be too long for Admin App. The maximum length is 150 characters.")
36+
.When(x => x.StreetNumberName != null);
37+
38+
RuleFor(m => m.State).NotEmpty();
39+
RuleFor(m => m.City).NotEmpty();
40+
RuleFor(m => m.City)
41+
.MaximumLength(30)
42+
.WithMessage("The City would be too long for Admin App. The maximum length is 30 characters.")
43+
.When(x => x.City != null);
44+
45+
RuleFor(m => m.ZipCode).NotEmpty();
46+
RuleFor(m => m.ZipCode)
47+
.MaximumLength(17)
48+
.WithMessage("The Zip Code would be too long for Admin App. The maximum length is 17 characters.")
49+
.When(x => x.ZipCode != null);
50+
51+
RuleFor(m => m.ApartmentRoomSuiteNumber)
52+
.MaximumLength(50)
53+
.WithMessage("The Suite would be too long for Admin App. The maximum length is 50 characters.")
54+
.When(x => x.ApartmentRoomSuiteNumber != null);
55+
}
56+
}
2257
}

Application/EdFi.Ods.AdminApp.Web/Models/ViewModels/EducationOrganizations/EditSchoolModel.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,32 @@ public abstract class EditSchoolModelValidatorBase<T> : AbstractValidator<T> whe
3737
{
3838
protected EditSchoolModelValidatorBase()
3939
{
40-
RuleFor(x => x.Name).NotEmpty();
41-
RuleFor(x => x.StreetNumberName).NotEmpty();
42-
RuleFor(x => x.City).NotEmpty();
40+
RuleFor(m => m.Name).NotEmpty();
41+
RuleFor(m => m.Name)
42+
.MaximumLength(75)
43+
.WithMessage("The School Name would be too long for Admin App. The maximum length is 75 characters.")
44+
.When(x => x.Name != null);
45+
46+
RuleFor(m => m.StreetNumberName).NotEmpty();
47+
RuleFor(m => m.StreetNumberName)
48+
.MaximumLength(150)
49+
.WithMessage("The Address would be too long for Admin App. The maximum length is 150 characters.")
50+
.When(x => x.StreetNumberName != null);
51+
52+
RuleFor(m => m.City).NotEmpty();
53+
RuleFor(m => m.City)
54+
.MaximumLength(30)
55+
.WithMessage("The City would be too long for Admin App. The maximum length is 30 characters.")
56+
.When(x => x.City != null);
57+
4358
RuleFor(x => x.State).NotEmpty();
44-
RuleFor(x => x.ZipCode).NotEmpty();
59+
60+
RuleFor(m => m.ZipCode).NotEmpty();
61+
RuleFor(m => m.ZipCode)
62+
.MaximumLength(17)
63+
.WithMessage("The Zip Code would be too long for Admin App. The maximum length is 17 characters.")
64+
.When(x => x.ZipCode != null);
65+
4566
RuleFor(x => x.GradeLevels).Must(x => x != null && x.Count > 0).WithMessage("You must choose at least one grade level");
4667
}
4768
}

Application/EdFi.Ods.AdminApp.Web/Views/EducationOrganizations/_AddPsiSchoolModal.cshtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ See the LICENSE and NOTICES files in the project root for more information.
2424
@Html.ValidationBlock()
2525
@Html.InputBlock(m => m.SchoolId).AddClass("reset-included")
2626
@Html.MultiSelectListBlock(m => m.GradeLevels, Model.GradeLevelOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value })
27-
@Html.InputBlock(m => m.Name).AddClass("reset-included")
28-
@Html.InputBlock(m => m.StreetNumberName).AddClass("reset-included")
29-
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber).AddClass("reset-included")
30-
@Html.InputBlock(m => m.City).AddClass("reset-included")
27+
@Html.InputBlock(m => m.Name, inputModifier: x => x.Attr("maxlength", "75")).AddClass("reset-included")
28+
@Html.InputBlock(m => m.StreetNumberName, inputModifier: x => x.Attr("maxlength", "150")).AddClass("reset-included")
29+
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber, inputModifier: x => x.Attr("maxlength", "50")).AddClass("reset-included")
30+
@Html.InputBlock(m => m.City, inputModifier: x => x.Attr("maxlength", "30")).AddClass("reset-included")
3131
@Html.SelectListBlock(m => m.State, Model.StateOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value })
32-
@Html.InputBlock(m => m.ZipCode).AddClass("reset-included")
32+
@Html.InputBlock(m => m.ZipCode, inputModifier: x => x.Attr("maxlength", "17")).AddClass("reset-included")
3333
if (Model.AccreditationStatusOptions != null && Model.AccreditationStatusOptions.Count > 1)
3434
{
3535
@Html.SelectListBlock(m => m.AccreditationStatus, Model.AccreditationStatusOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value })

Application/EdFi.Ods.AdminApp.Web/Views/EducationOrganizations/_AddSchoolModal.cshtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ See the LICENSE and NOTICES files in the project root for more information.
2424
@Html.ValidationBlock()
2525
@Html.InputBlock(m => m.SchoolId).AddClass("reset-included")
2626
@Html.MultiSelectListBlock(m => m.GradeLevels, Model.GradeLevelOptions, x => new SelectListItem {Text = x.DisplayText, Value = x.Value})
27-
@Html.InputBlock(m => m.Name).AddClass("reset-included")
28-
@Html.InputBlock(m => m.StreetNumberName).AddClass("reset-included")
29-
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber).AddClass("reset-included")
30-
@Html.InputBlock(m => m.City).AddClass("reset-included")
27+
@Html.InputBlock(m => m.Name, inputModifier: x => x.Attr("maxlength", "75")).AddClass("reset-included")
28+
@Html.InputBlock(m => m.StreetNumberName, inputModifier: x => x.Attr("maxlength", "150")).AddClass("reset-included")
29+
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber, inputModifier: x => x.Attr("maxlength", "50")).AddClass("reset-included")
30+
@Html.InputBlock(m => m.City, inputModifier: x => x.Attr("maxlength", "30")).AddClass("reset-included")
3131
@Html.SelectListBlock(m => m.State, Model.StateOptions, x => new SelectListItem {Text = x.DisplayText, Value = x.Value})
32-
@Html.InputBlock(m => m.ZipCode).AddClass("reset-included")
32+
@Html.InputBlock(m => m.ZipCode, inputModifier: x => x.Attr("maxlength", "17")).AddClass("reset-included")
3333
}
3434
</div>
3535
<div class="modal-footer">

Application/EdFi.Ods.AdminApp.Web/Views/EducationOrganizations/_EditPsiSchoolModal.cshtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ See the LICENSE and NOTICES files in the project root for more information.
2323
@Html.Input(m => m.PostSecondaryInstitutionId).Hide()
2424
@Html.ValidationBlock()
2525
@Html.MultiSelectListBlock(m => m.GradeLevels, Model.GradeLevelOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value, Selected = (Model.GradeLevels != null && Model.GradeLevels.Contains(x.Value)) })
26-
@Html.InputBlock(m => m.Name)
27-
@Html.InputBlock(m => m.StreetNumberName)
28-
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber)
29-
@Html.InputBlock(m => m.City)
26+
@Html.InputBlock(m => m.Name, inputModifier: x => x.Attr("maxlength", "75"))
27+
@Html.InputBlock(m => m.StreetNumberName, inputModifier: x => x.Attr("maxlength", "150"))
28+
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber, inputModifier: x => x.Attr("maxlength", "50"))
29+
@Html.InputBlock(m => m.City, inputModifier: x => x.Attr("maxlength", "30"))
3030
@Html.SelectListBlock(m => m.State, Model.StateOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value, Selected = Model.State == x.Value })
31-
@Html.InputBlock(m => m.ZipCode)
31+
@Html.InputBlock(m => m.ZipCode, inputModifier: x => x.Attr("maxlength", "17"))
3232
if (Model.AccreditationStatusOptions != null && Model.AccreditationStatusOptions.Count > 1)
3333
{
3434
@Html.SelectListBlock(m => m.AccreditationStatus, Model.AccreditationStatusOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value, Selected = Model.AccreditationStatus == x.Value})

Application/EdFi.Ods.AdminApp.Web/Views/EducationOrganizations/_EditSchoolModal.cshtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ See the LICENSE and NOTICES files in the project root for more information.
2323
@Html.Input(m => m.LocalEducationAgencyId).Hide()
2424
@Html.ValidationBlock()
2525
@Html.MultiSelectListBlock(m => m.GradeLevels, Model.GradeLevelOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value, Selected = (Model.GradeLevels != null && Model.GradeLevels.Contains(x.Value)) })
26-
@Html.InputBlock(m => m.Name)
27-
@Html.InputBlock(m => m.StreetNumberName)
28-
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber)
29-
@Html.InputBlock(m => m.City)
26+
@Html.InputBlock(m => m.Name, inputModifier: x => x.Attr("maxlength", "75"))
27+
@Html.InputBlock(m => m.StreetNumberName, inputModifier: x => x.Attr("maxlength", "150"))
28+
@Html.InputBlock(m => m.ApartmentRoomSuiteNumber, inputModifier: x => x.Attr("maxlength", "50"))
29+
@Html.InputBlock(m => m.City, inputModifier: x => x.Attr("maxlength", "30"))
3030
@Html.SelectListBlock(m => m.State, Model.StateOptions, x => new SelectListItem { Text = x.DisplayText, Value = x.Value, Selected = Model.State == x.Value })
31-
@Html.InputBlock(m => m.ZipCode)
31+
@Html.InputBlock(m => m.ZipCode, inputModifier: x => x.Attr("maxlength", "17"))
3232
}
3333
</div>
3434
<div class="modal-footer">

0 commit comments

Comments
 (0)