From 153fa60b2531bb56619a5ec3bb42a99850574e3d Mon Sep 17 00:00:00 2001 From: James Gunn Date: Mon, 13 Jan 2025 17:24:03 +0000 Subject: [PATCH] Replace asp-for attributes with for --- CHANGELOG.md | 7 +++ docs/components/character-count.md | 11 ++-- docs/components/checkboxes.md | 44 +++++++-------- docs/components/date-input.md | 54 +++++++++---------- docs/components/error-message.md | 14 ++--- docs/components/error-summary.md | 20 +++---- docs/components/file-upload.md | 32 +++++------ docs/components/radios.md | 44 +++++++-------- docs/components/select.md | 42 +++++++-------- docs/components/text-input.md | 18 +++---- docs/components/textarea.md | 36 ++++++------- samples/Samples.DateInput/Pages/Index.cshtml | 2 +- .../ErrorMessageWithModelStateError.cshtml | 2 +- .../ErrorSummaryWithModelStateError.cshtml | 2 +- .../TagHelpers/CharacterCountTagHelper.cs | 30 +++++------ .../TagHelpers/CheckboxesTagHelper.cs | 10 ++-- .../TagHelpers/DateInputTagHelper.cs | 28 +++++----- .../TagHelpers/ErrorMessageTagHelper.cs | 26 +++++---- .../TagHelpers/ErrorSummaryItemTagHelper.cs | 34 ++++++++---- .../TagHelpers/FileUploadTagHelper.cs | 6 +-- .../TagHelpers/FormGroupTagHelperBase.cs | 30 +++++++---- .../TagHelpers/RadiosTagHelper.cs | 8 +-- .../TagHelpers/SelectTagHelper.cs | 8 +-- .../TagHelpers/TextAreaTagHelper.cs | 8 +-- .../TagHelpers/TextInputTagHelper.cs | 31 +++++------ ...CustomDate.cshtml => ForCustomDate.cshtml} | 2 +- .../{AspForDate.cshtml => ForDate.cshtml} | 2 +- .../ErrorSummaryItemTagHelperTests.cs | 6 +-- 28 files changed, 299 insertions(+), 258 deletions(-) rename tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/{AspForCustomDate.cshtml => ForCustomDate.cshtml} (80%) rename tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/{AspForDate.cshtml => ForDate.cshtml} (81%) diff --git a/CHANGELOG.md b/CHANGELOG.md index c912a46f..abfe0a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Breaking changes + +#### `asp-for` attributes +The `asp-for` attribute is now obsolete; the `for` attribute should be used in its place. + ## 2.8.0 Targets GOV.UK Frontend v5.8.0. diff --git a/docs/components/character-count.md b/docs/components/character-count.md index 2b371a76..cf6d7326 100644 --- a/docs/components/character-count.md +++ b/docs/components/character-count.md @@ -26,17 +26,18 @@ Check out the [max words validator](../validation/maxwords.md) for adding server | Attribute | Type | Description | |----------------------------|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes, the content as well as the error message content. See [documentation on forms](forms.md) for more information. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes, the content as well as the error message content. See [documentation on forms](forms.md) for more information. | | `autocomplete` | `string` | The `autocomplete` attribute for the generated `textarea` element. | | `count-message-*` | | Additional attributes to add to the generated count message hint element. | | `disabled` | `bool` | Whether the textarea should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes, the content as well as the error message content. See [documentation on forms](forms.md) for more information. | | `form-group-*` | | Additional attributes to add to the generated form-group wrapper element. | | `id` | `string` | The `id` attribute for the generated `textarea` element. If not specified then a value is generated from the `name` attribute. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | | `label-class` | `string` | Additional classes for the generated `label` element. | | `max-length` | `int?` | The maximum number of characters the generated `textarea` may contain. Required unless the `max-words` attribute is specified. | | `max-words` | `int?` | The maximum number of words the generated `textarea` may contain. Required unless the `max-length` attribute is specified. | -| `name` | `string` | The `name` attribute for the generated `textarea` element. Required unless the `asp-for` attribute is specified. | +| `name` | `string` | The `name` attribute for the generated `textarea` element. Required unless the `for` attribute is specified. | | `rows` | `int` | The `rows` attribute for the generated `textarea` element. The default is `5`. | | `spellcheck` | `bool?` | The `spellcheck` attribute for the generated `textarea` element. The default is `null`. | | `textarea-*` | | Additional attributes to add to the generated `textarea` element. | @@ -57,7 +58,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -66,7 +67,7 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. diff --git a/docs/components/checkboxes.md b/docs/components/checkboxes.md index 2de969d1..4904a8af 100644 --- a/docs/components/checkboxes.md +++ b/docs/components/checkboxes.md @@ -141,13 +141,13 @@ ### `` -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | -| `checkboxes-*` | | Additional attributes to add to the generated container element that wraps the items. | -| `id-prefix` | `string` | The prefix to use when generating IDs for the hint, error message and items. If not specified then a value is generated from the `name` attribute. Required unless the `asp-for` attribute or `name` atribute is specified. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute or `id-prefix` attribute is specified. | +| Attribute | Type | Description | +|----------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `checkboxes-*` | | Additional attributes to add to the generated container element that wraps the items. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | +| `id-prefix` | `string` | The prefix to use when generating IDs for the hint, error message and items. If not specified then a value is generated from the `name` attribute. Required unless the `for` attribute or `name` atribute is specified. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `for` attribute or `id-prefix` attribute is specified. | ### `` @@ -161,8 +161,8 @@ Must be inside a `` element. The content is the HTML to use within the legend.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|-----------|-----------------------------------------------------------------------------------| | `is-page-heading` | `boolean` | Whether the legend also acts as the heading for the page. The default is `false`. | ### `` @@ -170,7 +170,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -179,13 +179,13 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` @@ -193,15 +193,15 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the label for the generated `input` element.\ Must be inside a `` or `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `checked` | `bool` | Whether the item should be checked. If this attribute is not specified but the `asp-for` attribute is specified on the parent `` then this value will be computed by comparing the `value` attribute with the model value; if the `value` attribute matches the string representation of the model or the model is a collection and the collection contains an entry whose string representation matches the `value` attribute then `checked` will be inferred to `true`. | -| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | -| `input-*` | | Additional attributes to add to the generated `input` element. | -| `label-*` | | Additional attributes to add to the generated `label` element. | -| `name` | string | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute or `name` attribute is specified on the parent ``. | -| `value` | `string` | *Required* The `value` attribute for the generated `input` element. | +| Attribute | Type | Description | +|------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `checked` | `bool` | Whether the item should be checked. If this attribute is not specified but the `for` attribute is specified on the parent `` then this value will be computed by comparing the `value` attribute with the model value; if the `value` attribute matches the string representation of the model or the model is a collection and the collection contains an entry whose string representation matches the `value` attribute then `checked` will be inferred to `true`. | +| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | +| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | +| `input-*` | | Additional attributes to add to the generated `input` element. | +| `label-*` | | Additional attributes to add to the generated `label` element. | +| `name` | string | The `name` attribute for the generated `input` element. Required unless the `for` attribute or `name` attribute is specified on the parent ``. | +| `value` | `string` | *Required* The `value` attribute for the generated `input` element. | ### `` diff --git a/docs/components/date-input.md b/docs/components/date-input.md index 3b65cf89..8a431058 100644 --- a/docs/components/date-input.md +++ b/docs/components/date-input.md @@ -79,22 +79,22 @@ The content is the HTML to use within the generated component. -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name-prefix`, `id` and `value` attributes as well as the error message content. The model type should be a `Date`, `DateTime` or a type that has a custom converter registered. See [custom date types](#custom-date-types) and [documentation on forms](forms.md) for more information. | -| `date-input-`*` | | Additional attributes for the container element that wraps the items. | -| `disabled` | `bool` | Whether the inputs should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the main component. Required unless the `asp-for` attribute is specified. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `name-prefix` | `string` | Optional prefix for the `name` attribute on each item's input. | -| `value` | `object` | The date to populate the item values with. The value should be a `Date`, `DateTime` or a type that has a custom converter registered. See [custom date types](#custom-date-types) for more information. | +| Attribute | Type | Description | +|----------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `date-input-`*` | | Additional attributes for the container element that wraps the items. | +| `disabled` | `bool` | Whether the inputs should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name-prefix`, `id` and `value` attributes as well as the error message content. The model type should be a `Date`, `DateTime` or a type that has a custom converter registered. See [custom date types](#custom-date-types) and [documentation on forms](forms.md) for more information. | +| `id` | `string` | The `id` attribute for the main component. Required unless the `for` attribute is specified. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `name-prefix` | `string` | Optional prefix for the `name` attribute on each item's input. | +| `value` | `object` | The date to populate the item values with. The value should be a `Date`, `DateTime` or a type that has a custom converter registered. See [custom date types](#custom-date-types) for more information. | ### `` The content is the HTML to use within the component's hint.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -103,20 +103,20 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | -| `error-items` | `DateInputErrorComponents?` | The components of the date that have errors (day, month and/or year). By default this is resolved by looking up the errors that occurred on model binding. The fallback is `DateInputErrorComponents.All`. | -| `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | +| Attribute | Type | Description | +|------------------------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `error-items` | `DateInputErrorComponents?` | The components of the date that have errors (day, month and/or year). By default this is resolved by looking up the errors that occurred on model binding. The fallback is `DateInputErrorComponents.All`. | +| `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` A container element used when date input content should be contained with a `fieldset` element. -When used every other child elemenet must be placed inside this element, not the root ``.\ +When used every other child element must be placed inside this element, not the root ``.\ Must be inside a `` element. ### `` @@ -125,22 +125,22 @@ Must be inside a `` element. The content is the HTML to use within the legend.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `is-page-heading` | `boolean` | Whether the legend also acts as the heading for the page. The default is `false`. | +| Attribute | Type | Description | +|--------------------|-----------|-----------------------------------------------------------------------------------| +| `is-page-heading` | `boolean` | Whether the legend also acts as the heading for the page. The default is `false`. | ### ``, ``, `` Must be inside a `` or `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `autocomplete` | `string` | The `autocomplete` attribute for the generated `input` element. | -| `id` | `string` | The `id` attribute for the item's geneated `input` element. | -| `inputmode` | `string` | The `inputmode` attribute for the item's generated `input` element. The default is `numeric`. | -| `name` | `string` | The `name` attribute for the item's generated `input` element. | -| `pattern` | `string` | The `pattern` attribute for the item's generated `input` element. The default is `[0-9]*`. | -| `value` | `int?` | The `value` attribute for the item's generated `input` element. | +| Attribute | Type | Description | +|------------------|----------|-----------------------------------------------------------------------------------------------| +| `autocomplete` | `string` | The `autocomplete` attribute for the generated `input` element. | +| `id` | `string` | The `id` attribute for the item's geneated `input` element. | +| `inputmode` | `string` | The `inputmode` attribute for the item's generated `input` element. The default is `numeric`. | +| `name` | `string` | The `name` attribute for the item's generated `input` element. | +| `pattern` | `string` | The `pattern` attribute for the item's generated `input` element. The default is `[0-9]*`. | +| `value` | `int?` | The `value` attribute for the item's generated `input` element. | ### ``, ``, `` diff --git a/docs/components/error-message.md b/docs/components/error-message.md index e760d39f..881bf538 100644 --- a/docs/components/error-message.md +++ b/docs/components/error-message.md @@ -21,7 +21,7 @@ ## Example - ModelState error ```razor - + ``` ![Error message](../images/error-message-with-modelstate-error.png) @@ -30,11 +30,11 @@ ### `` -The content is the HTML to use within the generated error message. Content is required if the `asp-for` attribute is not specified. +The content is the HTML to use within the generated error message. Content is required if the `for` attribute is not specified. -If `asp-for` is specified and there are no errors in `ModelState` then no output will be generated. If there are multiple errors only the first will be used. +If `for` is specified and there are no errors in `ModelState` then no output will be generated. If there are multiple errors only the first will be used. -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the error message. If content is specified this attribute is ignored. See [documentation on forms](../forms.md) for more information. | -| `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | +| Attribute | Type | Description | +|------------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `for` | `ModelExpression` | The model expression used to generate the error message. If content is specified this attribute is ignored. See [documentation on forms](../forms.md) for more information. | +| `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | diff --git a/docs/components/error-summary.md b/docs/components/error-summary.md index 745c31a1..3e939f44 100644 --- a/docs/components/error-summary.md +++ b/docs/components/error-summary.md @@ -33,7 +33,7 @@ To disable globally set the `PrependErrorSummaryToForms` property on `GovUkFront ```razor - + ``` @@ -43,8 +43,8 @@ To disable globally set the `PrependErrorSummaryToForms` property on `GovUkFront ### `` -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|----------------------|--------|-------------------------------------------------------------------------------------------------------------| | `disable-auto-focus` | `bool` | Whether to disable the behavior that focuses the error summary when the page loads. The default is `false`. | ### `` @@ -59,14 +59,14 @@ Must be inside a `` element. ### `` -The content is the HTML to use within the error link item. Content is required if the `asp-for` attribute is not specified.\ +The content is the HTML to use within the error link item. Content is required if the `for` attribute is not specified.\ -If `asp-for` is specified and there are no errors in `ModelState` then the item will not be rendered. +If `for` is specified and there are no errors in `ModelState` then the item will not be rendered. Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the error message. If content is specified this attribute is ignored. See [documentation on forms](../forms.md) for more information. | -| `link-*` | | Additional attributes to add to the generated `a` element. | -| (link attributes) | | If specified generates an `href` attribute using the specified values. See [documentation on links](../links.md) for more information. | +| Attribute | Type | Description | +|-------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `for` | `ModelExpression` | The model expression used to generate the error message. If content is specified this attribute is ignored. See [documentation on forms](../forms.md) for more information. | +| `link-*` | | Additional attributes to add to the generated `a` element. | +| (link attributes) | | If specified generates an `href` attribute using the specified values. See [documentation on links](../links.md) for more information. | diff --git a/docs/components/file-upload.md b/docs/components/file-upload.md index b9aadfac..fb2f7cd9 100644 --- a/docs/components/file-upload.md +++ b/docs/components/file-upload.md @@ -28,24 +28,24 @@ ### `` -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the error message content. See [documentation on forms](forms.md) for more information. | -| `described-by` | `string` | One or more element IDs to add to the `aria-describedby` attribute of the generated `input` element. | -| `disabled` | `bool` | Whether the input should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `input-*` | | Additional attributes to add to the generated `input` element. | -| `label-class` | `string` | Additional classes for the generated `label` element. | -| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute is specified. | +| Attribute | Type | Description | +|----------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `described-by` | `string` | One or more element IDs to add to the `aria-describedby` attribute of the generated `input` element. | +| `disabled` | `bool` | Whether the input should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the error message content. See [documentation on forms](forms.md) for more information. | +| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `input-*` | | Additional attributes to add to the generated `input` element. | +| `label-class` | `string` | Additional classes for the generated `label` element. | +| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `for` attribute is specified. | ### `` The content is the HTML to use within the component's label.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|--------|----------------------------------------------------------------------------------| | `is-page-heading` | `bool` | Whether the label also acts as the heading for the page. The default is `false`. | ### `` @@ -53,7 +53,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -62,11 +62,11 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | diff --git a/docs/components/radios.md b/docs/components/radios.md index 32e27f38..bc50752c 100644 --- a/docs/components/radios.md +++ b/docs/components/radios.md @@ -104,13 +104,13 @@ ### `` -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | -| `id-prefix` | `string` | The prefix to use when generating IDs for the hint, error message and items. If not specified then a value is generated from the `name` attribute. Required unless the `asp-for` attribute or `name` atribute is specified. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute or `id-prefix` attribute is specified. | -| `radios-*` | | Additional attributes to add to the generated container element that wraps the items. | +| Attribute | Type | Description | +|----------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | +| `id-prefix` | `string` | The prefix to use when generating IDs for the hint, error message and items. If not specified then a value is generated from the `name` attribute. Required unless the `for` attribute or `name` atribute is specified. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `for` attribute or `id-prefix` attribute is specified. | +| `radios-*` | | Additional attributes to add to the generated container element that wraps the items. | ### `` @@ -124,8 +124,8 @@ Must be inside a `` element. The content is the HTML to use within the legend.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|-----------|-----------------------------------------------------------------------------------| | `is-page-heading` | `boolean` | Whether the legend also acts as the heading for the page. The default is `false`. | ### `` @@ -133,7 +133,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -142,13 +142,13 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` or `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` @@ -156,15 +156,15 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the label for the generated `input` element.\ Must be inside a `` or `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `checked` | `bool` | Whether the item should be checked. If this attribute is not specified but the `asp-for` attribute is specified on the parent `` then this value will be computed by comparing the `value` attribute with the model value; if the `value` attribute matches the string representation of the model then `checked` will be inferred to `true`. | -| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | -| `input-*` | | Additional attributes to add to the generated `input` element. | -| `label-*` | | Additional attributes to add to the generated `label` element. | -| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute or `name` attribute is specified on the parent ``. | -| `value` | `string` | *Required* The `value` attribute for the generated `input` element. | +| Attribute | Type | Description | +|------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `checked` | `bool` | Whether the item should be checked. If this attribute is not specified but the `for` attribute is specified on the parent `` then this value will be computed by comparing the `value` attribute with the model value; if the `value` attribute matches the string representation of the model then `checked` will be inferred to `true`. | +| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | +| `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | +| `input-*` | | Additional attributes to add to the generated `input` element. | +| `label-*` | | Additional attributes to add to the generated `label` element. | +| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `for` attribute or `name` attribute is specified on the parent ``. | +| `value` | `string` | *Required* The `value` attribute for the generated `input` element. | ### `` diff --git a/docs/components/select.md b/docs/components/select.md index 3b44ebf5..7da5664b 100644 --- a/docs/components/select.md +++ b/docs/components/select.md @@ -20,24 +20,24 @@ ### `` -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | -| `described-by` | `string` | One or more element IDs to add to the `aria-describedby` attribute of the generated `select` element. | -| `disabled` | `bool` | Whether the element should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the generated `select` element. If not specified then a value is generated from the `name` attribute. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `label-class` | `string` | Additional classes for the generated `label` element. | -| `name` | `string` | The `name` attribute for the generated `select` element. Required unless the `asp-for` attribute is specified. | -| `select-*` | | Additional attributes to add to the generated `select` element. | +| Attribute | Type | Description | +|----------------------------|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `described-by` | `string` | One or more element IDs to add to the `aria-describedby` attribute of the generated `select` element. | +| `disabled` | `bool` | Whether the element should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes as well as the `selected` attribute for items and error message content. See [documentation on forms](forms.md) for more information. | +| `id` | `string` | The `id` attribute for the generated `select` element. If not specified then a value is generated from the `name` attribute. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `label-class` | `string` | Additional classes for the generated `label` element. | +| `name` | `string` | The `name` attribute for the generated `select` element. Required unless the `for` attribute is specified. | +| `select-*` | | Additional attributes to add to the generated `select` element. | ### `` The content is the HTML to use within the component's label.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|--------|----------------------------------------------------------------------------------| | `is-page-heading` | `bool` | Whether the label also acts as the heading for the page. The default is `false`. | ### `` @@ -45,7 +45,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -54,13 +54,13 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` @@ -68,8 +68,8 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the generated `option` element.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | -| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | -| `selected` | `bool` | Whether the item should be selected. If this attribute is not specified but the `asp-for` attribute is specified on the parent then this value will be computed by comparing the `value` attribute with the model value. The default is `false`. | -| `value` | `string` | The `value` attribute for the generated `option` element. | +| Attribute | Type | Description | +|------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `disabled` | `bool` | Whether the item should be disabled. The default is `false`. | +| `selected` | `bool` | Whether the item should be selected. If this attribute is not specified but the `for` attribute is specified on the parent then this value will be computed by comparing the `value` attribute with the model value. The default is `false`. | +| `value` | `string` | The `value` attribute for the generated `option` element. | diff --git a/docs/components/text-input.md b/docs/components/text-input.md index cf6a763e..ac3624bc 100644 --- a/docs/components/text-input.md +++ b/docs/components/text-input.md @@ -46,17 +46,17 @@ The content is the HTML to use within the generated component. | Attribute | Type | Description | |----------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `asp-for` | `ModelExpression` | The model expression used to generate the `name`, `id` and `value` attributes as well as the error message content. See [documentation on forms](forms.md) for more information. | | `autocomplete` | `string` | The `autocomplete` attribute for the generated `input` element. | | `autocapitalize` | `string` | The `autocapitalize` attribute for the generated `input` element. | | `described-by` | `string` | One or more element IDs to add to the `aria-describedby` attribute of the generated `input` element. | | `disabled` | `bool` | Whether the input should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name`, `id` and `value` attributes as well as the error message content. See [documentation on forms](forms.md) for more information. | | `id` | `string` | The `id` attribute for the generated `input` element. If not specified then a value is generated from the `name` attribute. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | | `input-*` | | Additional attributes to add to the generated `input` element. | | `input-wrapper-*` | | Additional attributes to add to the element that wraps the generated `input` element. | | `label-class` | `string` | Additional classes for the generated `label` element. | -| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `asp-for` attribute is specified. | +| `name` | `string` | The `name` attribute for the generated `input` element. Required unless the `for` attribute is specified. | | `inputmode` | `string` | The `inputmode` attribute for the generated `input` element. | | `pattern` | `string` | The `pattern` attribute for the generated `input` element. | | `spellcheck` | `bool?` | The `spellcheck` attribute for the generated `input` element. The default is `null`. | @@ -68,8 +68,8 @@ The content is the HTML to use within the generated component. The content is the HTML to use within the component's label.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|--------|----------------------------------------------------------------------------------| | `is-page-heading` | `bool` | Whether the label also acts as the heading for the page. The default is `false`. | ### `` @@ -77,7 +77,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -86,13 +86,13 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` diff --git a/docs/components/textarea.md b/docs/components/textarea.md index 18c1ad23..fe0b85b0 100644 --- a/docs/components/textarea.md +++ b/docs/components/textarea.md @@ -22,26 +22,26 @@ ### `` -| Attribute | Type | Description | -| --- | --- | --- | -| `asp-for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes, the content as well as the error message content. See [documentation on forms](forms.md) for more information. | -| `autocomplete`| `string` | The `autocomplete` attribute for the generated `textarea` element. | -| `disabled` | `bool` | Whether the textarea should be disabled. The default is `false`. | -| `id` | `string` | The `id` attribute for the generated `textarea` element. If not specified then a value is generated from the `name` attribute. | -| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `asp-for` attribute should be ignored when generating an error message. The default is `false`. | -| `label-class` | `string` | Additional classes for the generated `label` element. | -| `name` | `string` | The `name` attribute for the generated `textarea` element. Required unless the `asp-for` attribute is specified. | -| `rows` | `int` | The `rows` attribute for the generated `textarea` element. The default is `5`. | -| `spellcheck` | `bool?` | The `spellcheck` attribute for the generated `textarea` element. The default is `null`. | -| `textarea-*` | | Additional attributes to add to the generated `textarea` element. | +| Attribute | Type | Description | +|----------------------------|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `autocomplete` | `string` | The `autocomplete` attribute for the generated `textarea` element. | +| `disabled` | `bool` | Whether the textarea should be disabled. The default is `false`. | +| `for` | `ModelExpression` | The model expression used to generate the `name` and `id` attributes, the content as well as the error message content. See [documentation on forms](forms.md) for more information. | +| `id` | `string` | The `id` attribute for the generated `textarea` element. If not specified then a value is generated from the `name` attribute. | +| `ignore-modelstate-errors` | `bool` | Whether ModelState errors on the ModelExpression specified by the `for` attribute should be ignored when generating an error message. The default is `false`. | +| `label-class` | `string` | Additional classes for the generated `label` element. | +| `name` | `string` | The `name` attribute for the generated `textarea` element. Required unless the `for` attribute is specified. | +| `rows` | `int` | The `rows` attribute for the generated `textarea` element. The default is `5`. | +| `spellcheck` | `bool?` | The `spellcheck` attribute for the generated `textarea` element. The default is `null`. | +| `textarea-*` | | Additional attributes to add to the generated `textarea` element. | ### `` The content is the HTML to use within the component's label.\ Must be inside a `` element. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|-------------------|--------|----------------------------------------------------------------------------------| | `is-page-heading` | `bool` | Whether the label also acts as the heading for the page. The default is `false`. | ### `` @@ -49,7 +49,7 @@ Must be inside a `` element. The content is the HTML to use within the component's hint.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ +If the `for` attribute is specified on the parent `` then content for the hint will be generated from the model expression.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. @@ -58,13 +58,13 @@ If you want to retain the generated content and specify additional attributes th The content is the HTML to use within the component's error message.\ Must be inside a `` element. -If the `asp-for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. +If the `for` attribute is specified on the parent `` then content for the error message will be generated from the model expression. (To prevent this set `ignore-modelstate-errors` on the parent `` to `false`.) Specifying any content here will override any generated error message.\ If you want to retain the generated content and specify additional attributes then use a self-closing tag e.g. ``. -| Attribute | Type | Description | -| --- | --- | --- | +| Attribute | Type | Description | +|------------------------|----------|-----------------------------------------------------------------------------------| | `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. | ### `` diff --git a/samples/Samples.DateInput/Pages/Index.cshtml b/samples/Samples.DateInput/Pages/Index.cshtml index 7316f24b..4b940695 100644 --- a/samples/Samples.DateInput/Pages/Index.cshtml +++ b/samples/Samples.DateInput/Pages/Index.cshtml @@ -5,7 +5,7 @@ }
- + diff --git a/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorMessage/ErrorMessageWithModelStateError.cshtml b/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorMessage/ErrorMessageWithModelStateError.cshtml index 7229fdac..e76d1fc3 100644 --- a/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorMessage/ErrorMessageWithModelStateError.cshtml +++ b/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorMessage/ErrorMessageWithModelStateError.cshtml @@ -1,4 +1,4 @@ @page @model ErrorMessageWithModelStateErrorModel - + diff --git a/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorSummary/ErrorSummaryWithModelStateError.cshtml b/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorSummary/ErrorSummaryWithModelStateError.cshtml index 4259a24d..5eebe70a 100644 --- a/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorSummary/ErrorSummaryWithModelStateError.cshtml +++ b/src/GovUk.Frontend.AspNetCore.DocSamples/Pages/ErrorSummary/ErrorSummaryWithModelStateError.cshtml @@ -2,5 +2,5 @@ @model ErrorSummaryWithModelStateErrorModel - + diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/CharacterCountTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/CharacterCountTagHelper.cs index f475b124..bda2e94f 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/CharacterCountTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/CharacterCountTagHelper.cs @@ -68,18 +68,18 @@ internal CharacterCountTagHelper(IComponentGenerator componentGenerator, IModelH /// An expression to be evaluated against the current model. /// [HtmlAttributeName(AspForAttributeName)] - //[Obsolete("Use the 'for' attribute instead.")] - public ModelExpression? AspFor { get; set; } - /*{ + [Obsolete("Use the 'for' attribute instead.")] + public ModelExpression? AspFor + { get => For; set => For = value; - }*/ + } - ///// - ///// An expression to be evaluated against the current model. - ///// - //[HtmlAttributeName(ForAttributeName)] - //public ModelExpression? For { get; set; } + /// + /// An expression to be evaluated against the current model. + /// + [HtmlAttributeName(ForAttributeName)] + public ModelExpression? For { get; set; } /// /// The autocomplete attribute for the generated textarea element. @@ -256,9 +256,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu var name = ResolveName(); var id = ResolveId(name); var value = ResolveValue(characterCountContext); - var labelOptions = characterCountContext.GetLabelOptions(AspFor, ViewContext!, _modelHelper, id, AspForAttributeName); - var hintOptions = characterCountContext.GetHintOptions(AspFor, _modelHelper); - var errorMessageOptions = characterCountContext.GetErrorMessageOptions(AspFor, ViewContext!, _modelHelper, IgnoreModelStateErrors); + var labelOptions = characterCountContext.GetLabelOptions(For, ViewContext!, _modelHelper, id, AspForAttributeName); + var hintOptions = characterCountContext.GetHintOptions(For, _modelHelper); + var errorMessageOptions = characterCountContext.GetErrorMessageOptions(For, ViewContext!, _modelHelper, IgnoreModelStateErrors); if (LabelClass is not null) { @@ -341,14 +341,14 @@ private IHtmlContent ResolveId(IHtmlContent name) private IHtmlContent ResolveName() { - if (Name is null && AspFor is null) + if (Name is null && For is null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( NameAttributeName, AspForAttributeName); } - return new HtmlString(Name ?? _modelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name)); + return new HtmlString(Name ?? _modelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name)); } private IHtmlContent? ResolveValue(CharacterCountContext characterCountContext) @@ -358,6 +358,6 @@ private IHtmlContent ResolveName() return characterCountContext.Value; } - return AspFor != null ? new HtmlString(_modelHelper.GetModelValue(ViewContext!, AspFor.ModelExplorer, AspFor.Name)) : null; + return For is not null ? new HtmlString(_modelHelper.GetModelValue(ViewContext!, For.ModelExplorer, For.Name)) : null; } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/CheckboxesTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/CheckboxesTagHelper.cs index ae2a2ae4..e021a903 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/CheckboxesTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/CheckboxesTagHelper.cs @@ -64,7 +64,7 @@ internal CheckboxesTagHelper(IGovUkHtmlGenerator? htmlGenerator = null, IModelHe [HtmlAttributeName(NameAttributeName)] public string? Name { get; set; } - private protected override FormGroupContext CreateFormGroupContext() => new CheckboxesContext(Name, AspFor); + private protected override FormGroupContext CreateFormGroupContext() => new CheckboxesContext(Name, For); private protected override IHtmlContent GenerateFormGroupContent( TagHelperContext tagHelperContext, @@ -133,12 +133,12 @@ private protected override string ResolveIdPrefix() return IdPrefix; } - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( IdPrefixAttributeName, NameAttributeName, - AspForAttributeName); + ForAttributeName); } TryResolveName(out var resolvedName); @@ -149,13 +149,13 @@ private protected override string ResolveIdPrefix() private bool TryResolveName([NotNullWhen(true)] out string? name) { - if (Name == null && AspFor == null) + if (Name == null && For == null) { name = default; return false; } - name = Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name); + name = Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name); return true; } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/DateInputTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/DateInputTagHelper.cs index f52b3a1b..65adb284 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/DateInputTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/DateInputTagHelper.cs @@ -112,7 +112,7 @@ public object? Value } private protected override FormGroupContext CreateFormGroupContext() => - new DateInputContext(haveExplicitValue: _valueSpecified, AspFor); + new DateInputContext(haveExplicitValue: _valueSpecified, For); private protected override IHtmlContent GenerateFormGroupContent( TagHelperContext tagHelperContext, @@ -176,21 +176,21 @@ private protected override string GetErrorFieldId(TagHelperContext context) private protected override string ResolveIdPrefix() { - if (AspFor == null && Id == null) + if (For == null && Id == null) { ThrowHelper.AtLeastOneOfAttributesMustBeSpecified(AspForAttributeName, IdAttributeName); } return Id ?? TagBuilder.CreateSanitizedId( - ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name), + ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name), Constants.IdAttributeDotReplacement); } private TagBuilder GenerateDateInput(DateInputContext dateInputContext, bool haveError) { var resolvedId = ResolveIdPrefix(); - var resolvedName = AspFor != null ? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor.Name) : null; + var resolvedName = For != null ? ModelHelper.GetFullHtmlFieldName(ViewContext!, For.Name) : null; // This is a deliberate deviation from the GDS implementation so it works better with ASP.NET Core's model binding system var resolvedNamePrefix = NamePrefix != null ? NamePrefix + "." : @@ -199,7 +199,7 @@ private TagBuilder GenerateDateInput(DateInputContext dateInputContext, bool hav var dateInputModelConverters = _options.DateInputModelConverters; - var valueAsDate = GetValueAsDate() ?? (AspFor != null ? GetValueFromModel() : null); + var valueAsDate = GetValueAsDate() ?? (For != null ? GetValueFromModel() : null); var errorItems = GetErrorComponents(dateInputContext); var day = CreateDateInputItem( @@ -253,7 +253,7 @@ DateInputItem CreateDateInputItem( var resolvedItemValue = contextItem?.ValueSpecified == true ? (contextItem.Value?.ToString() ?? string.Empty) : _valueSpecified ? getComponentFromValue(valueAsDate) : contextItem?.ValueSpecified == true ? contextItem.Value?.ToString() : - AspFor != null ? GetValueFromModelState() : + For != null ? GetValueFromModelState() : null; var resolvedItemId = contextItem?.Id ?? $"{resolvedId}.{contextItem?.Name ?? defaultName}"; @@ -284,7 +284,7 @@ DateInputItem CreateDateInputItem( string? GetValueFromModelState() { - Debug.Assert(AspFor != null); + Debug.Assert(For != null); // Can't use ModelHelper.GetModelValue here; // custom Date types may not expose components via Day/Month/Year properties. @@ -294,7 +294,7 @@ DateInputItem CreateDateInputItem( // If that fails, get the model and convert it to a Date using options.DateInputModelConverters. // From that extract the Day/Month/Year. - var expression = $"{AspFor.Name}.{defaultName}"; + var expression = $"{For.Name}.{defaultName}"; var modelStateKey = ModelHelper.GetFullHtmlFieldName(ViewContext!, expression); if (ViewContext!.ModelState.TryGetValue(modelStateKey, out var modelStateEntry) && @@ -330,10 +330,10 @@ DateInputItem CreateDateInputItem( DateOnly? GetValueFromModel() { - Debug.Assert(AspFor != null); + Debug.Assert(For != null); - var modelValue = AspFor!.Model; - var underlyingModelType = Nullable.GetUnderlyingType(AspFor.ModelExplorer.ModelType) ?? AspFor.ModelExplorer.ModelType; + var modelValue = For!.Model; + var underlyingModelType = Nullable.GetUnderlyingType(For.ModelExplorer.ModelType) ?? For.ModelExplorer.ModelType; if (modelValue is null) { @@ -361,15 +361,15 @@ private DateInputErrorComponents GetErrorComponents(DateInputContext dateInputCo return dateInputContext.ErrorComponents.Value; } - if (AspFor == null) + if (For == null) { return DateInputErrorComponents.All; } - Debug.Assert(AspFor != null); + Debug.Assert(For != null); Debug.Assert(ViewContext != null); - var fullName = ModelHelper.GetFullHtmlFieldName(ViewContext, AspFor.Name); + var fullName = ModelHelper.GetFullHtmlFieldName(ViewContext, For.Name); if (_dateInputParseErrorsProvider.TryGetErrorsForModel(fullName, out var parseErrors)) { diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs index 24c58927..a9eb909e 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs @@ -22,6 +22,7 @@ public class ErrorMessageTagHelper : TagHelper internal const string TagName = "govuk-error-message"; private const string AspForAttributeName = "asp-for"; + private const string ForAttributeName = "for"; private const string VisuallyHiddenTextAttributeName = "visually-hidden-text"; private readonly IGovUkHtmlGenerator _htmlGenerator; @@ -46,12 +47,19 @@ internal ErrorMessageTagHelper( /// /// An expression to be evaluated against the current model. /// - /// - /// If specified and this element has no child content the error message will be resolved from - /// the errors on this expression's . - /// [HtmlAttributeName(AspForAttributeName)] - public ModelExpression? AspFor { get; set; } + [Obsolete("Use the 'for' attribute instead.")] + public ModelExpression? AspFor + { + get => For; + set => For = value; + } + + /// + /// An expression to be evaluated against the current model. + /// + [HtmlAttributeName(ForAttributeName)] + public ModelExpression? For { get; set; } /// /// The visually hidden prefix used before the error message. @@ -82,19 +90,19 @@ await output.GetChildContentAsync() : childContent = output.Content; } - if (childContent == null && AspFor == null) + if (childContent == null && For == null) { throw new InvalidOperationException( $"Cannot determine content. Element must contain content if the '{AspForAttributeName}' attribute is not specified."); } IHtmlContent? resolvedContent = childContent; - if (resolvedContent == null && AspFor != null) + if (resolvedContent == null && For != null) { var validationMessage = _modelHelper.GetValidationMessage( ViewContext!, - AspFor.ModelExplorer, - AspFor.Name); + For.ModelExplorer, + For.Name); if (validationMessage != null) { diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorSummaryItemTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorSummaryItemTagHelper.cs index ae62a094..2ab5dca6 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorSummaryItemTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorSummaryItemTagHelper.cs @@ -23,6 +23,7 @@ public class ErrorSummaryItemTagHelper : TagHelper internal const string TagName = "govuk-error-summary-item"; private const string AspForAttributeName = "asp-for"; + private const string ForAttributeName = "for"; private const string LinkAttributesPrefix = "link-"; private readonly GovUkFrontendAspNetCoreOptions _options; @@ -53,7 +54,18 @@ internal ErrorSummaryItemTagHelper( /// An expression to be evaluated against the current model. /// [HtmlAttributeName(AspForAttributeName)] - public ModelExpression? AspFor { get; set; } + [Obsolete("Use the 'for' attribute instead.")] + public ModelExpression? AspFor + { + get => For; + set => For = value; + } + + /// + /// An expression to be evaluated against the current model. + /// + [HtmlAttributeName(ForAttributeName)] + public ModelExpression? For { get; set; } /// /// Additional attributes to add to the generated a element. @@ -71,10 +83,10 @@ internal ErrorSummaryItemTagHelper( /// public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { - if (output.TagMode == TagMode.SelfClosing && AspFor == null) + if (output.TagMode == TagMode.SelfClosing && For == null) { throw new InvalidOperationException( - $"Content is required when the '{AspForAttributeName}' attribute is not specified."); + $"Content is required when the '{ForAttributeName}' attribute is not specified."); } var errorSummaryContext = context.GetContextItem(); @@ -94,12 +106,12 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu } else { - Debug.Assert(AspFor != null); + Debug.Assert(For != null); var validationMessage = _modelHelper.GetValidationMessage( ViewContext!, - AspFor!.ModelExplorer, - AspFor.Name); + For!.ModelExplorer, + For.Name); if (validationMessage == null) { @@ -116,10 +128,10 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu resolvedHref = hrefAttribute.Value.ToString(); output.Attributes.Remove(hrefAttribute); } - else if (AspFor != null) + else if (For != null) { var errorFieldId = TagBuilder.CreateSanitizedId( - _modelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name), + _modelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name), Constants.IdAttributeDotReplacement); // Date inputs are special; they don't have an element with ID which exactly corresponds to the name derived above; @@ -135,7 +147,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu { var dateInputErrorComponents = DateInputErrorComponents.All; - if (_dateInputParseErrorsProvider.TryGetErrorsForModel(AspFor.Name, out var dateInputParseErrors)) + if (_dateInputParseErrorsProvider.TryGetErrorsForModel(For.Name, out var dateInputParseErrors)) { dateInputErrorComponents = dateInputParseErrors.GetErrorComponents(); } @@ -171,9 +183,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu bool IsModelExpressionForDate() { - Debug.Assert(AspFor != null); + Debug.Assert(For != null); - var modelType = Nullable.GetUnderlyingType(AspFor!.Metadata.ModelType) ?? AspFor!.Metadata.ModelType; + var modelType = Nullable.GetUnderlyingType(For!.Metadata.ModelType) ?? For!.Metadata.ModelType; return _options.DateInputModelConverters.Any(c => c.CanConvertModelType(modelType)); } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/FileUploadTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/FileUploadTagHelper.cs index cb9fadab..1b88ed6c 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/FileUploadTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/FileUploadTagHelper.cs @@ -130,7 +130,7 @@ private protected override string ResolveIdPrefix() return Id; } - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( IdAttributeName, @@ -145,13 +145,13 @@ private protected override string ResolveIdPrefix() private string ResolveName() { - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( NameAttributeName, AspForAttributeName); } - return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name); + return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name); } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/FormGroupTagHelperBase.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/FormGroupTagHelperBase.cs index 3dcbd98f..7c8b5807 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/FormGroupTagHelperBase.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/FormGroupTagHelperBase.cs @@ -18,6 +18,7 @@ namespace GovUk.Frontend.AspNetCore.TagHelpers; public abstract class FormGroupTagHelperBase : TagHelper { private protected const string AspForAttributeName = "asp-for"; + private protected const string ForAttributeName = "for"; private protected const string IgnoreModelStateErrorsAttributeName = "ignore-modelstate-errors"; private protected FormGroupTagHelperBase( @@ -32,7 +33,18 @@ private protected FormGroupTagHelperBase( /// An expression to be evaluated against the current model. /// [HtmlAttributeName(AspForAttributeName)] - public ModelExpression? AspFor { get; set; } + [Obsolete("Use the 'for' attribute instead.")] + public ModelExpression? AspFor + { + get => For; + set => For = value; + } + + /// + /// An expression to be evaluated against the current model. + /// + [HtmlAttributeName(ForAttributeName)] + public ModelExpression? For { get; set; } /// /// Whether the for the expression should be used @@ -126,12 +138,12 @@ private protected virtual TagBuilder CreateTagBuilder(bool haveError, IHtmlConte var content = formGroupContext.ErrorMessage?.Content; var attributes = formGroupContext.ErrorMessage?.Attributes; - if (content == null && AspFor != null && IgnoreModelStateErrors != true) + if (content == null && For != null && IgnoreModelStateErrors != true) { var validationMessage = ModelHelper.GetValidationMessage( ViewContext!, - AspFor!.ModelExplorer, - AspFor.Name); + For!.ModelExplorer, + For.Name); if (validationMessage != null) { @@ -174,9 +186,9 @@ void AddErrorToFormErrorContext() var content = formGroupContext.Hint?.Content; var attributes = formGroupContext.Hint?.Attributes; - if (content == null && AspFor != null) + if (content == null && For != null) { - var description = ModelHelper.GetDescription(AspFor.ModelExplorer); + var description = ModelHelper.GetDescription(For.ModelExplorer); if (description != null) { @@ -200,7 +212,7 @@ void AddErrorToFormErrorContext() internal IHtmlContent GenerateLabel(FormGroupContext formGroupContext, string? labelClass) { // We need some content for the label; if AspFor is null then label content must have been specified - if (AspFor == null && formGroupContext.Label?.Content == null) + if (For == null && formGroupContext.Label?.Content == null) { throw new InvalidOperationException( $"Label content must be specified when the '{AspForAttributeName}' attribute is not specified."); @@ -215,7 +227,7 @@ internal IHtmlContent GenerateLabel(FormGroupContext formGroupContext, string? l attributes.MergeCssClass(labelClass); var resolvedContent = content ?? - new HtmlString(HtmlEncoder.Default.Encode(ModelHelper.GetDisplayName(AspFor!.ModelExplorer, AspFor.Name) ?? string.Empty)); + new HtmlString(HtmlEncoder.Default.Encode(ModelHelper.GetDisplayName(For!.ModelExplorer, For.Name) ?? string.Empty)); return Generator.GenerateLabel(resolvedIdPrefix, isPageHeading, resolvedContent, attributes); } @@ -223,7 +235,7 @@ internal IHtmlContent GenerateLabel(FormGroupContext formGroupContext, string? l internal IHtmlContent ResolveFieldsetLegendContent(FormGroupFieldsetContext fieldsetContext) { var resolvedFieldsetLegendContent = fieldsetContext.Legend?.Content ?? - (AspFor is not null ? new HtmlString(HtmlEncoder.Default.Encode(ModelHelper.GetDisplayName(AspFor.ModelExplorer, AspFor.Name) ?? string.Empty)) : null); + (For is not null ? new HtmlString(HtmlEncoder.Default.Encode(ModelHelper.GetDisplayName(For.ModelExplorer, For.Name) ?? string.Empty)) : null); if (resolvedFieldsetLegendContent is null) { diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/RadiosTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/RadiosTagHelper.cs index 2ea5e8f0..1b45d863 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/RadiosTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/RadiosTagHelper.cs @@ -64,7 +64,7 @@ internal RadiosTagHelper(IGovUkHtmlGenerator? htmlGenerator = null, IModelHelper [HtmlAttributeName(DictionaryAttributePrefix = RadiosAttributesPrefix)] public IDictionary? RadiosAttributes { get; set; } = new Dictionary(); - private protected override FormGroupContext CreateFormGroupContext() => new RadiosContext(Name, AspFor); + private protected override FormGroupContext CreateFormGroupContext() => new RadiosContext(Name, For); private protected override IHtmlContent GenerateFormGroupContent( TagHelperContext tagHelperContext, @@ -131,7 +131,7 @@ private protected override string ResolveIdPrefix() return IdPrefix; } - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( IdPrefixAttributeName, @@ -147,13 +147,13 @@ private protected override string ResolveIdPrefix() private bool TryResolveName([NotNullWhen(true)] out string? name) { - if (Name == null && AspFor == null) + if (Name == null && For == null) { name = default; return false; } - name = Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name); + name = Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name); return true; } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/SelectTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/SelectTagHelper.cs index d941b7c9..ca5da1ad 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/SelectTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/SelectTagHelper.cs @@ -87,7 +87,7 @@ internal SelectTagHelper(IGovUkHtmlGenerator? htmlGenerator = null, IModelHelper [HtmlAttributeName(DictionaryAttributePrefix = AttributesPrefix)] public IDictionary? SelectAttributes { get; set; } = new Dictionary(); - private protected override FormGroupContext CreateFormGroupContext() => new SelectContext(AspFor); + private protected override FormGroupContext CreateFormGroupContext() => new SelectContext(For); private protected override IHtmlContent GenerateFormGroupContent( TagHelperContext tagHelperContext, @@ -145,7 +145,7 @@ private protected override string ResolveIdPrefix() return Id; } - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( IdAttributeName, @@ -160,13 +160,13 @@ private protected override string ResolveIdPrefix() private string ResolveName() { - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( NameAttributeName, AspForAttributeName); } - return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name); + return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name); } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/TextAreaTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/TextAreaTagHelper.cs index 23cd73c2..3dd176d1 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/TextAreaTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/TextAreaTagHelper.cs @@ -142,7 +142,7 @@ TagBuilder GenerateTextArea(bool haveError) var resolvedName = ResolveName(); var resolvedContent = textAreaContext.Value ?? - new HtmlString(AspFor != null ? HtmlEncoder.Default.Encode(ModelHelper.GetModelValue(ViewContext!, AspFor.ModelExplorer, AspFor.Name) ?? string.Empty) : string.Empty); + new HtmlString(For != null ? HtmlEncoder.Default.Encode(ModelHelper.GetModelValue(ViewContext!, For.ModelExplorer, For.Name) ?? string.Empty) : string.Empty); var resolvedTextAreaAttributes = TextAreaAttributes.ToAttributeDictionary(); resolvedTextAreaAttributes.MergeCssClass("govuk-js-textarea"); @@ -168,7 +168,7 @@ private protected override string ResolveIdPrefix() return Id; } - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( IdAttributeName, @@ -183,13 +183,13 @@ private protected override string ResolveIdPrefix() private string ResolveName() { - if (Name == null && AspFor == null) + if (Name == null && For == null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( NameAttributeName, AspForAttributeName); } - return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name); + return Name ?? ModelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name); } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/TextInputTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/TextInputTagHelper.cs index ef2bdd71..27505e8e 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/TextInputTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/TextInputTagHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -79,18 +80,18 @@ internal TextInputTagHelper(IComponentGenerator componentGenerator, IModelHelper /// An expression to be evaluated against the current model. /// [HtmlAttributeName(AspForAttributeName)] - //[Obsolete("Use the 'for' attribute instead.")] - public ModelExpression? AspFor { get; set; } - /*{ + [Obsolete("Use the 'for' attribute instead.")] + public ModelExpression? AspFor + { get => For; set => For = value; - }*/ + } - ///// - ///// An expression to be evaluated against the current model. - ///// - //[HtmlAttributeName(ForAttributeName)] - //public ModelExpression? For { get; set; } + /// + /// An expression to be evaluated against the current model. + /// + [HtmlAttributeName(ForAttributeName)] + public ModelExpression? For { get; set; } /// /// The autocapitalize attribute for the generated input element. @@ -229,9 +230,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu var name = ResolveName(); var id = ResolveId(name); var value = ResolveValue(); - var labelOptions = textInputContext.GetLabelOptions(AspFor, ViewContext!, _modelHelper, id, AspForAttributeName); - var hintOptions = textInputContext.GetHintOptions(AspFor, _modelHelper); - var errorMessageOptions = textInputContext.GetErrorMessageOptions(AspFor, ViewContext!, _modelHelper, IgnoreModelStateErrors); + var labelOptions = textInputContext.GetLabelOptions(For, ViewContext!, _modelHelper, id, AspForAttributeName); + var hintOptions = textInputContext.GetHintOptions(For, _modelHelper); + var errorMessageOptions = textInputContext.GetErrorMessageOptions(For, ViewContext!, _modelHelper, IgnoreModelStateErrors); var prefixOptions = textInputContext.GetPrefixOptions(); var suffixOptions = textInputContext.GetSuffixOptions(); @@ -304,14 +305,14 @@ private IHtmlContent ResolveId(IHtmlContent name) private IHtmlContent ResolveName() { - if (Name is null && AspFor is null) + if (Name is null && For is null) { throw ExceptionHelper.AtLeastOneOfAttributesMustBeProvided( NameAttributeName, AspForAttributeName); } - return new HtmlString(Name ?? _modelHelper.GetFullHtmlFieldName(ViewContext!, AspFor!.Name)); + return new HtmlString(Name ?? _modelHelper.GetFullHtmlFieldName(ViewContext!, For!.Name)); } private IHtmlContent? ResolveValue() @@ -321,6 +322,6 @@ private IHtmlContent ResolveName() return new HtmlString(_value); } - return AspFor != null ? new HtmlString(_modelHelper.GetModelValue(ViewContext!, AspFor.ModelExplorer, AspFor.Name)) : null; + return For is not null ? new HtmlString(_modelHelper.GetModelValue(ViewContext!, For.ModelExplorer, For.Name)) : null; } } diff --git a/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForCustomDate.cshtml b/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForCustomDate.cshtml similarity index 80% rename from tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForCustomDate.cshtml rename to tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForCustomDate.cshtml index 458f640a..d5cc2941 100644 --- a/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForCustomDate.cshtml +++ b/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForCustomDate.cshtml @@ -1,7 +1,7 @@ @model GovUk.Frontend.AspNetCore.IntegrationTests.DateInputsTestsModel - + Save diff --git a/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForDate.cshtml b/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForDate.cshtml similarity index 81% rename from tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForDate.cshtml rename to tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForDate.cshtml index a6352ceb..dd33c47a 100644 --- a/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/AspForDate.cshtml +++ b/tests/GovUk.Frontend.AspNetCore.IntegrationTests/DateInputTestsViews/ForDate.cshtml @@ -1,7 +1,7 @@ @model GovUk.Frontend.AspNetCore.IntegrationTests.DateInputsTestsModel
- + Save diff --git a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorSummaryItemTagHelperTests.cs b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorSummaryItemTagHelperTests.cs index 5c2bd9c7..2158d3b4 100644 --- a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorSummaryItemTagHelperTests.cs +++ b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorSummaryItemTagHelperTests.cs @@ -57,7 +57,7 @@ public async Task ProcessAsync_AddsItemToContext() } [Fact] - public async Task ProcessAsync_NoContentOrAspNetFor_ThrowsInvalidOperationException() + public async Task ProcessAsync_NoContentOrFor_ThrowsInvalidOperationException() { // Arrange var errorSummaryContext = new ErrorSummaryContext(); @@ -91,11 +91,11 @@ public async Task ProcessAsync_NoContentOrAspNetFor_ThrowsInvalidOperationExcept // Assert Assert.IsType(ex); - Assert.Equal("Content is required when the 'asp-for' attribute is not specified.", ex.Message); + Assert.Equal("Content is required when the 'for' attribute is not specified.", ex.Message); } [Fact] - public async Task ProcessAsync_AspForSpecified_UsesModelStateErrorMessageForContent() + public async Task ProcessAsync_ForSpecified_UsesModelStateErrorMessageForContent() { // Arrange var errorSummaryContext = new ErrorSummaryContext();