Skip to content

Document the optionDisabled attribute of the select tag - #17159

Open
matrei wants to merge 1 commit into
7.0.xfrom
docs/select-option-disabled
Open

matrei wants to merge 1 commit into
7.0.xfrom
docs/select-option-disabled

Conversation

@matrei

@matrei matrei commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

<g:select> has supported optionDisabled since Grails 2.4 (GRAILS-8494), but the attribute was never added to the tag reference or to the @attr Javadoc of the tag. Someone noticed this on the users mailing list.

  • Adds optionDisabled to the reference page, with an example, and to the @attr list in FormTagLib.
  • Documents two limits of the current behavior: the attribute is only used together with optionKey, and the option of the current value is never disabled, because a browser does not submit a disabled option.
  • Adds tests for the property name and closure forms and for both limits. No test covered the attribute before.

This changes no behavior.

The select tag has supported optionDisabled since Grails 2.4, but
neither the tag reference nor the @attr Javadoc of the tag listed it.

Document the attribute, including two limits of its current behavior:
it is only used together with optionKey, and the option of the current
value is never disabled, because a browser does not submit a disabled
option. Add tests for the property name and closure forms and for both
limits.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. The note leaves out that a keys list turns optionDisabled off.

* `value` (optional) - The current selected value that evaluates equals() to `true` for one of the elements in the `from` list.
* `optionKey` (optional) - By default, the `value` attribute of each `<option>` element will be the result of a `toString()` call on each element. Setting this allows the value to be a bean property of each element in the list.
* `optionValue` (optional) - By default, the body of each `<option>` element will be the result of a `toString()` call on each element in the `from` attribute list. Setting this allows the value to be a bean property of each element in the list.
* `optionDisabled` (optional) - Disables some of the `<option>` elements. Either the name of a bean property of each element in the `from` list, or a Closure that accepts an element, such as `optionDisabled="${{ it.stock == 0 }}"`. The `<option>` element is disabled when the result is `true` (Groovy truth). Only used together with `optionKey`. The `<option>` element of the current `value` is never disabled, because a browser does not submit a disabled option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example uses optionDisabled and optionKey. Adding a keys list makes the second book selectable even though it is out of print, because keys skips optionDisabled. Say to leave keys out when using optionDisabled.

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI assisted review

Docs and tests match FormTagLib. Agree with @jamesfredley: keys takes precedence over optionKey, so optionDisabled is ignored when keys is set. Please add "and without keys" to the "Only used together with optionKey" sentence in both select.adoc and the @attr Javadoc. LGTM otherwise.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants