[beta5] Single checkbox/radio error class/message

Created on 26 October 2023, about 1 year ago
Updated 9 November 2023, about 1 year ago

Problem/Motivation

If a single checkbox/radio is required, when submitting the form, there is an error (visible in the global error message), but there is no inline error message on the related input, and no error style applied on it (should be red with a border on the left).

This problem only occurs on single checkbox/radio : when it's multiple options, there is an error message on the radio/checkbox group, and a global error style as well.

Proposed resolution

I've realized this is caused by the conditions on $variables['element']['#delta'] in ui_suite_dsfr_preprocess_form_element() : this variable doesn't exist, so "add_error" is always false.
My suggestion would be to use $variables['element']['#error_no_message'] instead, which seems to fit exactly that purpose (in the reverse way).

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France mh_nichts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mh_nichts
  • Status changed to Needs review about 1 year ago
  • 🇦🇷Argentina tguerineau

    Hi,

    I've looked into the issue regarding the single checkbox/radio error class/message and have identified the root cause.
    I've attached a patch that implements this fix. Here's what I've changed:

    1- Replaced the condition checking for #delta with #error_no_message to determine if an error should be added.
    2- Adjusted the logic for setting the $error_class variable based on this new condition.

    Please test the patch. Looking forward to feedback!

  • Assigned to pdureau
  • 🇫🇷France pdureau Paris

    thanks, I will have a look

  • Issue was unassigned.
  • Status changed to Needs work about 1 year ago
  • 🇫🇷France pdureau Paris

    Looks great. Can you do a git MR instead of a patch?

  • Status changed to Needs review about 1 year ago
  • 🇦🇷Argentina tguerineau

    Certainly!

    I've created a Merge Request (MR) with the changes.

    Let me know if there's anything else needed. Thank you!

  • 🇫🇷France pdureau Paris

    I see your commit: https://git.drupalcode.org/issue/ui_suite_dsfr-3396957/-/commit/b654066b...

    It is a great and I want to merge it, but I don't find the MR (and I don't know how to create it myself. I guess you have to create it).

  • Status changed to Needs work about 1 year ago
  • @tguerineau opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇦🇷Argentina tguerineau

    Thank you for your feedback!

    My apologies for the oversight. I've now created the MR. You can review and merge it. Appreciate your patience!

  • Status changed to Fixed about 1 year ago
  • 🇫🇷France pdureau Paris

    Merged, thanks

  • 🇫🇷France mh_nichts

    Hello,

    Thanks to both of you for the quick actions !

    However I'm afraid there is a typo in the fix, on line 217 : the condition should be on $variables['add_error'] instead of !$variables['add_error'] (= the error class should be added only if "add_error" is true).

  • Status changed to Needs work about 1 year ago
  • 🇫🇷France pdureau Paris

    Thanks a lot.

    Tom'as can you have a look? I guess it is possible to add a commit in the MR.

  • 🇦🇷Argentina tguerineau

    Hi @pdureau and @mh_nichts,

    Thank you for the catch! I've reviewed the code and you're correct about the error class condition.

    I've made the necessary update and pushed the commit.
    I've observed that my latest commit addressing the error class condition is present in the repository on the original branch, which confirms the push was successful. However, this update isn't reflected on the changes page linked from the issue.

    Could anyone clarify if I should create a new merge request for this fix, or if there is another step I should take?

    Appreciate your help on the next steps.

  • 🇫🇷France pdureau Paris

    Hello,

    Could anyone clarify if I should create a new merge request for this fix, or if there is another step I should take?

    I am more familiar with the "vanilla" gitlab workflow than the Drupal one, so I was bealieving you can add a new commit in your already merged but still available MR: https://git.drupalcode.org/project/ui_suite_dsfr/-/merge_requests/40

    Anyway, if you can"t do that, no need for a new issue. You can create a new fork or a new branch in the actual issue.

  • @tguerineau opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇦🇷Argentina tguerineau

    Hi @pdureau,

    Following up on the recent discussion, I've created a new branch 3396957-Single-checkbox-radio-error with the updated fix where I've removed the ! operator as suggested. I've pushed this branch and created a new merge request to address the typo mentioned earlier.

    Here's the link to the new merge request for review.

    I look forward to any reviews or comments.

  • 🇫🇷France pdureau Paris

    Merged. Credit given to both tguerineau & mh_nichts.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024