-
Notifications
You must be signed in to change notification settings - Fork 1
HEEDLS-643 Fix character limit error on admin fields and registration… #684
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
Changes from all commits
2b30372
9b6d0bd
c3f00b1
476accb
ba2b0de
28c60d3
2c201eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ string action | |
| SaveAction => EditAdminFieldPostSave(customisationId, model), | ||
| AddPromptAction => AdminFieldAnswersPostAddPrompt(model), | ||
| BulkAction => EditAdminFieldBulk(customisationId, model), | ||
| _ => new StatusCodeResult(500) | ||
| _ => new StatusCodeResult(500), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -192,7 +192,7 @@ public IActionResult AddAdminField(int customisationId, AddAdminFieldViewModel m | |
| SaveAction => AddAdminFieldPostSave(customisationId, model), | ||
| AddPromptAction => AdminFieldAnswersPostAddPrompt(model), | ||
| BulkAction => AddAdminFieldBulk(customisationId, model), | ||
| _ => new StatusCodeResult(500) | ||
| _ => new StatusCodeResult(500), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -307,7 +307,7 @@ private void SetEditAdminFieldTempData(EditAdminFieldViewModel model) | |
| id.ToString(), | ||
| new CookieOptions | ||
| { | ||
| Expires = CookieExpiry | ||
| Expires = CookieExpiry, | ||
| } | ||
| ); | ||
| TempData.Set(data); | ||
|
|
@@ -359,7 +359,7 @@ private void SetAddAdminFieldTempData(AddAdminFieldViewModel model) | |
| id.ToString(), | ||
| new CookieOptions | ||
| { | ||
| Expires = CookieExpiry | ||
| Expires = CookieExpiry, | ||
| } | ||
| ); | ||
| TempData.Set(data); | ||
|
|
@@ -470,15 +470,23 @@ string optionsString | |
|
|
||
| private void SetTotalAnswersLengthTooLongError(AdminFieldAnswersViewModel model) | ||
| { | ||
| if (model.OptionsString == null || model.OptionsString.Length < 2) | ||
| if (model.OptionsString == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var remainingLength = 1000 - (model.OptionsString?.Length - 2 ?? 0); | ||
| var remainingLength = 1000 - model.OptionsString.Length; | ||
| var remainingLengthShownToUser = remainingLength <= 2 ? 0 : remainingLength - 2; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we think it is clear enough to just show zero if the answer is over the limit? I'm wondering about showing how many characters are over the limit so the user knows how much they need to shorten their answer by. But then that might introduce confusion if they then want to add another answer which will mysteriously be another 2 characters shorter. Do we think its not worth the bother? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm right. I think it would be useful to know how many characters you've entered so you can compare it against the number remaining, and I think it would be more useful than confusing. This error will probably not be encountered very often, and I think it would be more useful than confusing. Added in the number of characters entered to the error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just need to fix the tests accordingly, will do after lunch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this looks pretty good. Minor suggestion, I think it would be better if it said "x characters were entered" to make it slightly clearer that those characters are the ones the user just tried to enter. Does that sound reasonable? |
||
| var answerLength = model.Answer!.Length; | ||
| var remainingLengthPluralitySuffix = DisplayStringHelper.GetPluralitySuffix(remainingLengthShownToUser); | ||
| var answerLengthPluralitySuffix = DisplayStringHelper.GetPluralitySuffix(answerLength); | ||
| var verb = answerLength == 1 ? "was" : "were"; | ||
|
|
||
| ModelState.AddModelError( | ||
| nameof(AdminFieldAnswersViewModel.Answer), | ||
| $"The complete list of answers must be 1000 characters or fewer ({remainingLength} characters remaining for the new answer)" | ||
| "The complete list of answers must be 1000 characters or fewer " + | ||
| $"({remainingLengthShownToUser} character{remainingLengthPluralitySuffix} remaining for the new answer, " + | ||
| $"{answerLength} character{answerLengthPluralitySuffix} {verb} entered)" | ||
| ); | ||
| } | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.