Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced the input tag to include a disabled attribute #601

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

pmoreno-rodriguez
Copy link
Contributor

The 'checkboxes' field defines a set of checkboxes, but actually when the code references 'field.xxxx' it is referring to 'checkboxes', not to each individual checkbox, so with the current code, you cannot disable an individual checkbox in the set.
There is one scenario where this could be useful. A site developer might want to display some checkboxes inside a checkboxes field, disabled, just to inform the user, which can then be used in some twig template.
With these changes, I intend to improve the behavior of the checkboxes field so that you can choose which checkboxes are disabled.

Added

  • Added conditional disabling of checkboxes based on disabled_options.
  • Added custom styles (opacity and cursor) for labels of disabled checkboxes.

Changed

  • Moved the for loop inside the <div> element for better structure and readability.
  • Enhanced the input tag to include a disabled attribute check.
  • Improved the label styling to reflect the state of the associated

@pmoreno-rodriguez
Copy link
Contributor Author

pmoreno-rodriguez commented Oct 20, 2024

Blueprint example for disabled option included in this pull request:

cookies.categories:
      type: checkboxes
      label: THEME.ADMIN.THEME.COOKIES.CATEGORIES_LABEL
      style: vertical
      help: THEME.ADMIN.THEME.COOKIES.CATEGORIES_HELP
      default:
        necessary: true
        functionality: false
        analytics: false
        marketing: false
      options:
        necessary: THEME.ADMIN.THEME.COOKIES.NECESSARY
        functionality: THEME.ADMIN.THEME.COOKIES.FUNCTIONALITY
        analytics: THEME.ADMIN.THEME.COOKIES.ANALYTICS
        marketing: THEME.ADMIN.THEME.COOKIES.MARKETING
      help_options:
        necessary: THEME.ADMIN.THEME.COOKIES.NECESSARY_HELP
      use: keys
      disabled_options:
        - necessary
      validate:
        type: commalist

In this example, necessary option will appear disabled in admin.

checkboxes_disabled

@rhukster
Copy link
Member

Before I accept and merge this do you mind creating a PR for the learn docs? https://learn.getgrav.org/17/forms/forms/fields-available#checkboxes-field

@pmoreno-rodriguez
Copy link
Contributor Author

Updated docs in PR1105

@rhukster rhukster merged commit afbaf13 into getgrav:develop Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants