Skip to content

Commit

Permalink
Replace asp-for attributes with for
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Jan 13, 2025
1 parent 7f1e129 commit c2febe5
Show file tree
Hide file tree
Showing 35 changed files with 378 additions and 337 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 6 additions & 5 deletions docs/components/character-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -57,7 +58,7 @@ Must be inside a `<govuk-character-count>` element.
The content is the HTML to use within the component's hint.\
Must be inside a `<govuk-character-count>` element.

If the `asp-for` attribute is specified on the parent `<govuk-character-count>` then content for the hint will be generated from the model expression.\
If the `for` attribute is specified on the parent `<govuk-character-count>` 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.
`<govuk-character-count-hint class="some-additional-class" />`.

Expand All @@ -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 `<govuk-character-count>` element.

If the `asp-for` attribute is specified on the parent `<govuk-character-count>` then content for the error message will be generated from the model expression.
If the `for` attribute is specified on the parent `<govuk-character-count>` then content for the error message will be generated from the model expression.
(To prevent this set `ignore-modelstate-errors` on the parent `<govuk-character-count>` 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.
`<govuk-character-count-error-message visually-hidden-text="Error" />`.
Expand Down
44 changes: 22 additions & 22 deletions docs/components/checkboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@

### `<govuk-checkboxes>`

| 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. |

### `<govuk-checkboxes-fieldset>`

Expand All @@ -161,16 +161,16 @@ Must be inside a `<govuk-checkboxes>` element.
The content is the HTML to use within the legend.\
Must be inside a `<govuk-checkboxes-fieldset>` 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`. |

### `<govuk-checkboxes-hint>`

The content is the HTML to use within the component's hint.\
Must be inside a `<govuk-checkboxes>` or `<govuk-checkboxes-fieldset>` element.

If the `asp-for` attribute is specified on the parent `<govuk-checkboxes>` then content for the hint will be generated from the model expression.\
If the `for` attribute is specified on the parent `<govuk-checkboxes>` 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.
`<govuk-checkboxes-hint class="some-additional-class" />`.

Expand All @@ -179,29 +179,29 @@ 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 `<govuk-checkboxes>` or `<govuk-checkboxes-fieldset>` element.

If the `asp-for` attribute is specified on the parent `<govuk-checkboxes>` then content for the error message will be generated from the model expression.
If the `for` attribute is specified on the parent `<govuk-checkboxes>` then content for the error message will be generated from the model expression.
(To prevent this set `ignore-modelstate-errors` on the parent `<govuk-checkboxes>` 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.
`<govuk-checkboxes-error-message visually-hidden-text="Error" />`.

| Attribute | Type | Description |
| --- | --- | --- |
| Attribute | Type | Description |
|------------------------|----------|-----------------------------------------------------------------------------------|
| `visually-hidden-text` | `string` | The visually hidden prefix used before the error message. The default is `Error`. |

### `<govuk-checkboxes-item>`

The content is the HTML to use within the label for the generated `input` element.\
Must be inside a `<govuk-checkboxes>` or `<govuk-checkboxes-fieldset>` 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 `<govuk-checkboxes>` 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 `<govuk-checkboxes>`. |
| `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 `<govuk-checkboxes>` 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 `<govuk-checkboxes>`. |
| `value` | `string` | *Required* The `value` attribute for the generated `input` element. |

### `<govuk-checkboxes-item-conditional>`

Expand Down
Loading

0 comments on commit c2febe5

Please sign in to comment.