Problem/Motivation
In certain cases we want to disable duplicate messages (on top - summary - and inline).
We currently have the #error_no_message
property which allowed us to disable errors messages for individual elements.
There may be some field that does not display the inline error, so the message is only visible in the summary. As an example, the Captcha field.
We should then keep the messages in the summary - even when the new property to disable the summary is requested - for fields that contain errors but can't display them inline (Eg. invisible elements, missing elements, ...).
Proposed resolution
Add a form property which can be used to disable IFE summary$form['#disable_inline_form_errors_summary'] = TRUE
.
Keep the message in the summary for fields which can't show inline-error (Eg. invisible elements, missing elements, ...).
Completed tasks
Write a patch.Update the patch as requested in #17 (numbered points). (Done by #20, #24, #26).Issue summary update requested in #17.Write tests. (Done by #20, #24).Write ainline_form_errors.api.php
where we can document how both of these works. See #17Write a patch for #3027318: Improve test coverage for Inline Form Errors Improve test coverage for Inline Form Errors
Remaining tasks
Once #3027318: Improve test coverage for Inline Form Errors merged, address issue #29- Review and commit.
User interface changes
- Developers will be able to remove the Summary message when IFE is enable.
- The summary should still be visible for an element which can't show inline-error (invisible element, missing element, ...).
API changes
The form element will have an optional #disable_inline_form_errors_summary boolean
, that if TRUE
, disables the duplicate messages from summary & inline-error elements. If one or more elements with errors can't show inline-error (Eg. invisible elements, missing elements, ...) , the summary will remain visible with those messages only.
Summary generated with AI on April 20, 2023
Note that this summary has not yet been validated by a human.
The issue is about adding a possibility to disable the Inline Form Errors summary. This is useful in cases where you want to show only the inline errors, but not the summary with links to them. For example, this could be useful for AJAX forms, where you don't want the big red box at the top of the page.
The proposed solution is to add a new property to the form element, called #disable_inline_form_errors_summary. This property can be set to TRUE to disable the summary.
The patch has been written and tested, and it is ready to be merged.
The next steps are to update the issue summary and to get the patch merged.
Comment | File | Size | Author |
---|---|---|---|
#108 | 2880011-nr-bot.txt | 2.77 KB | needs-review-queue-bot |
#107 | interdiff_106-107.txt | 707 bytes | vsujeetkumar |
#107 | 2880011-107.patch | 4.28 KB | vsujeetkumar |
| |||
#106 | 2880011-106.patch | 3.87 KB | _utsavsharma |
#106 | interdiff_103-106.txt | 791 bytes | _utsavsharma |
Issue fork drupal-2880011
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nikunjkotechaAdding patch with suggested solution (it should work fine for 8.3.x as well)
Comment #3
nikunjkotechaRemoving unwanted diff from patch.
Comment #4
nikunjkotechaComment #6
dmsmidtThanks for the request and your work, there is already an issue for this however. #2856950: Add a possibility to disable inline form errors for a complete form
Comment #7
nikunjkotechaHi @dmsmidt, case here is different (let me know if description needs updating)
Here, we need inline form errors but not the errors on top and the one you referred is for disabling inline form errors completely.
Comment #8
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commented@nikunjkotecha - I think your use case needs more detail.
Please clarify: what do you expect to see at the top of the page? A design mockup (or screenshot with notes) may help here.
At minimum, we should have a red message block which says: "there are errors in the form." Otherwise a user would need to read through the entire form again, as far as the first error, to even know there was an error present at all.
Comment #9
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedI don't think this qualifies as major, until we get a better idea of what is being proposed.
Comment #10
nikunjkotechaSimply nothing on top, just inline errors.
There are cases where we use AJAX to submit the form (for instance - newsletter subscription block in footer) where we don't want the big red box and only the error below the fields. It works great with this module but it still shows at both the places. We need a way to disable errors on top for this and many such use-cases IMO.
Let me know if we still need mockup / more detail here.
Comment #11
dmsmidtThanks @nikunjkotecha for the explanation and your work.
We have an earlier request that asks for the same #2841040: Allow disabling the Inline Form Errors summary (yep, found another one), I'm closing that one in favor of this because there has been more progress here.
For me it is a clear enough request now, but I have some additional thoughts.
I guess we also want to be able to prevent the summary for only partial AJAX form replacements. So allow the summary for the complete form, but disable it when for example only a fieldset is reloaded/submitted/validated via AJAX.
I think the property
error_no_message
is not clear enough, or can be confusing. The whole property is a bit of a mess anyhow. I think it was introduced to counter the error bubbling behaviour and display of duplicate messaged for compound fields like dates and checkboxes. Currently it means something like: highlight the field/RenderElement as having an error, but don't show the inline error message and don't show a summary link to it. This meaning wouldn't apply to the usage proposed by @nikunjkotecha, since it would hide a non-inline message.For example
disable_inline_form_errors_summary
, is already more fitting, and more in line with #2856950: Add a possibility to disable inline form errors for a complete form.This could applied to the whole form or to any other child RenderElement and their children.
Let's discuss this and update the IS accordingly.
In any case this would need tests.
Comment #12
nikunjkotecha@dmsmidt completely agree with your last comment. Will try to update the patch with what you mentioned and will have a look to the last patch and discussions in #2856950
Comment #13
nikunjkotechaComment #14
nikunjkotechaComment #16
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedThe last patch works as expected.
I suggest to add a settings form where can configure on which form i want the inline form feature, and where i don't want the summary.
this will be really better.
Thanks,
Comment #17
alexpottWe need to add an inline_form_errors.api.php where we can document how both of these work.
This is a negative test we should assert the case where drupalSetMessage gets called here too so that if this changes we know to change this test.
Comment #19
philipsoares CreditAttribution: philipsoares commentedThere may be some field that does not display the inline error, only in the summary. As an example the Captcha field.
I modified the patch to not display in the summary the fields that contain errors in line, but to display the others, so that they are not hidden.
Comment #20
wengerkRe-roll the patch from #13 as #19 does not apply.
I also add the changes suggested by #19.
1. We still need to add an
inline_form_errors.api.php
where we can document how both of these work ;2. We still need an issue summary update ;
3. I'm not sure how I apply the suggestion of #17.2 (so please review my changes, any feedback appreciate).
Comment #21
wengerkComment #22
wengerkComment #23
Krzysztof Domański1. Test testDisplayErrorMessagesNoSummary() needs work. It passes even if #disable_inline_form_errors_summary is FALSE.
2. An additional condition (see note 2 below) is not necessary.
It is similar to the following code:
3. If #disable_inline_form_errors_summary is set to TRUE $errors and $error_links will be empty after loop. This means that the code behind the loop will not show messages.
In this case, I think it is better to check #disable_inline_form_errors_summary at the beginning, instead of doing it in each iteration.
Comment #24
wengerkThanks for your review !
I mad a huge mistake on #22 by not reading properly #19.
I had to change #22 for the reasons explain by #19 - I'm sorry for my mistake.
Because we had this issue, #23.2 & #23.3 was then non applicable.
Here are my changes :
- Use the patch from #19 instead of #13
- Refactor the tests of #20
1. We still need to add an inline_form_errors.api.php where we can document how both of these work ;
2. We still need an issue summary update ;
3. I'm not sure how I apply the suggestion of #17.2 (so please review my changes, any feedback appreciate).
Comment #26
wengerkUse
Link::fromTextAndUrl
instead ofl
function.1. We still need to add an inline_form_errors.api.php where we can document how both of these work (any example of issue doing it well would help me or the next one to finalize this step) ;
2. We still need an issue summary update ;
3. I'm not sure how I apply the suggestion of #17.2 (so please review my changes, any feedback appreciate).
Comment #27
wengerkComment #28
wengerkAdd the API changes on issue summary.
Comment #29
Krzysztof DomańskiI was reviewing and this works great! I have suggestion.
1. Now we're testing the form with only one field in the
testDisplayErrorMessagesInlineNoSummary()
andtestDisplayErrorMessagesNotInlineWithSummary()
.I think we should also test the remaining fields with errors (e.g. missing or invisible fields).
Can we define a multi-field form in the setUp() method?
Then check more test cases.
2. Typo in the function name.
Comment #30
wengerkThanks for review:
Yep why not.
It would be great to have only 1 form generation (the one used in the first test seems pretty good & complete). Then use it in every other tests.
But it would be an out-of-scoop change. We should create a child-issue which focuses on this change (make the tests easier to read by using only 1 Form in the Setup). Then refactor our Class & tests added here.
I don’t want to apply any change on already existing tests here (refactoring of Setup function) which is out-of-scoop of this issue.
What do you think ? Can you create this issue & start the refactoring Class (form creation in Setup). Then we will be able to backport this change here & progress on this issue ?
Yep sorry ^^
Comment #31
Krzysztof DomańskiGood point!
#3027318: Improve test coverage for Inline Form Errors
Comment #32
wengerkUpdate completed tasks & remaining ones.
Comment #33
wengerkAdd links to blocker issue #3027318
Comment #34
wengerkComment #36
Krzysztof DomańskiThe blocker issue #3027318: Improve test coverage for Inline Form Errors has been fixed.
Comment #37
mpp CreditAttribution: mpp as a volunteer and at AmeXio commented#26 needs a reroll
Comment #38
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #39
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedRerolled #26 against 8.8, fixed typo and updated tests.
Comment #40
mpp CreditAttribution: mpp as a volunteer and at AmeXio for District09 commentedComment #41
Krzysztof Domański1. Addressed issue #29.
2. Still needs
inline_form_errors.api.php
(#17) so back to "Needs work".Comment #42
Krzysztof DomańskiI added
inline_form_errors.api.php
.Comment #43
Diego_Mow CreditAttribution: Diego_Mow as a volunteer and at CI&T commentedWorked fine for me.
RTBC
Comment #44
Krzysztof DomańskiI added change record Allow disabling the Inline Form Errors summary.
Comment #47
Krzysztof DomańskiUnrelated test failure. Back to RTBC.
Comment #48
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedHello, I've just tested this myself and it works great. I already have use cases for it too. Another vote for being committed.
Comment #49
irene_dobbs CreditAttribution: irene_dobbs at Bounteous commentedHello, I am using this for my forms on 8.8.4 and it works great!
Comment #50
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedHello, it worked for us as well on 8.7.9 thanks!
Comment #52
xjmApologies for the delayed patch review here.
@dmsmidt said in #11 that he did not think this was a sufficiently clear machine name, but that's already present in HEAD, so out of scope to change it here.
The URL here should probably use
@link
/@endlink
.Hmm, a unit test does not seem like the right choice here. That said, since the module is already using unit tests, that might be out of scope. I would have used a browser test, or additionally provided a browser test.
Should be "missing elements" (plural).
"and with no title" also doesn't make sense in context.
Maybe the comment should be:
Retitling to make it clear that this is API-only, not a UI feature. Thanks!
Comment #53
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedWorking on this.
Comment #54
dmsmidtThanks you for picking this up again @xjm, and all the work by the others!
But... from what I read, I'm not convinced these changes are clear enough.
Inline Form Errors adds multiple API only properties to allow for certain edge cases. Sadly these are needed because of how the form-api and rendering trees work. These edge cases are legit, so we should account for them.
And it needs to be totally clear what the different IFE Form API properties do and when to use what.
From the review from @xjm I take away we describe the workings of the properties not clear enough in the code and DO documentation.
1
For example #52 point 4:
One: We are creating too much code complexity here with nested if/elses.
Two: Because of the complexity we need to add comments.
Three: The proposed rewriting of the comment to `If inline errors are disabled, do not show the links and summary. Retain the message if the field is not shown or cannot display inline errors.` misses the point. We are not disabling IFE, just trying to disable summary of inline errors.
So, let's create clearly named helper methods and/or move the logic to the point where we add the summary message.
2
Also we still need an IS and Change Record update. It looks like 'duplicate messages' are the problem. But that is IMHO not what we are trying to do. Because IFE doesn't make duplicate messages, it just also generates a summary (one message) of all inline form errors with fragment/hash/anchor links to them.
3
Further, from the IS and CR 'There may be some field that does not display the inline error, so the message is only visible in the summary.'
If a form element error is not 'inline', it is never in the summary message to begin with right? It will just have its own message outside the 'summary message' in the area we print messages. So this is a non-concern right? Let's update the IS/CR.
4
Last but not least about the current test.
I partly agree with @xjm this test would probably be easier to understand as a functional/browser test.
Unit test is faster though ;-) So as long we are confident and it is clear I'm ok with it.
(4.1) Please do show a test only failing patch so that we know the fix works without trying ourselves.
(4.2)
The description is far more clear than the method name, but we can improve both.
'testDisabledInlineErrorsSummary'
`Tests that disabling the inline errors summary works`
(4.3)
Euh? This is not what we want to test. Just test we don't have a summary at all. Other errors should have their own normal non-inline messages. Test one thing per test method and we don't need comments.
(4.4)
So this checks there is no summary rendered? Not really obvious what is testing that there is no summary. Could use a comment.
(4.5)
Funky message: this is no message. Just use a clear 'fake' message.
(4.5)
Testing that 'all the rest' still works after disabling the summary seems legit, but now we are testing multiple things in one test method. We should split this, and can't we just set the disabled property and call a different test method that does this already (or is that evil)?
My apologisch for the long wait, keep up the good work.
Comment #55
dmsmidt(duplicate)
Comment #56
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #57
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI am not very experienced with PHPUnit so I have left that alone for now. Here is what I accomplished with this patch :
#52 : 2, 3, 4, 6
I have changed the wording of these comments based on suggestions.
#54 : 1
I have inverted one of the if statements to allow for use to just
continue
early, this reduced the nesting used. I'd just like to add, complexity does not mean you need comments, it means you need less complexity. A helper function would not be suitable here. The continue statements clearly show a path with minimal branching.#54 : 4.2, 4.3
I've renamed the test and cleaned up the comments.
Perhaps later I will see if I can do something with changing the actual tests. For now, I invite anyone to pick up that bit as they are not my strong suit.
Though I have not addressed the test concerns, I am changing this to needs review as there have been changes.
Comment #58
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedI think the API documentation (and change record) should clearly mention accessibility and usability implications. Some cautionary advice, similar to the "accessibility considerations" section now included in many MDN articles.
I'm not against this API feature, but it isn't something that should be used frequently or casually. I'll have a think about how to phrase this.
The main risk I want to highlight when disabling the summary message, is that the first mention of an error can occur outside the browser viewport just after page load (a.k.a. "below the fold"). In this case, users may be unaware that there are any errors at all, and mistakenly think their form submission was successful.
Any user could run into this situation; it isn't just about users with disabilities. However some users and situations can be more seriously impacted:
EDIT (14th June 2020): This issue is still lacks good use cases, IMO.
I'm not convinced that "the form uses AJAX" amounts to a use case here, because it doesn't say anything about the context or purpose of the form. The form submission mechanism doesn't have anything to do with the need for error reporting.
So far we just have @nikunjkotecha's "Newsletter signup block in the footer" - but what's the significant feature there? Is it the small number of fields, the location, or something else?
Comment #59
attisanAlmost all forms with few (or a single) elements could benefit and are thus use cases. Having a login-form with multiple red alerts isn't exactly visually pleasing.
I would generally argue, that good use cases can't be provided beforehand in all cases and that more options tend to be the better way for an open-minded framework (like drupal).
Comment #60
jcnventura CreditAttribution: jcnventura at 1xINTERNET commentedI know this is supposed to be about reducing complexity, but really? Replacing one line with 4 new code lines (and 2 comment lines), it is improving the code? Also, please don't use
continue
if you can avoid it. It's easy to not use it. Just do the new code inside the existing elseif block.Comment #61
deepakkumar14 CreditAttribution: deepakkumar14 as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedThe patch #57 was no longer applied so added a re-rolled patch with above mentioned changes by #60.
Comment #63
deepakkumar14 CreditAttribution: deepakkumar14 as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedAdded another patch hope it works.
Comment #64
deepakkumar14 CreditAttribution: deepakkumar14 as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #66
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedComment #67
longwave+1 to adding this. I am already using a version of this patch on a site; my use case is that the UX/design includes inline form errors across several forms but no summary, so to satisfy the design requirements I had to remove the summary. Doing this without this patch is non trivial as IFE already alters the form messages to move the errors inline and add the summary; subsequently removing the summary again is even more complicated.
However, is it worth negating the option here? We don't have many "disable" options in Drupal; instead should we name the flag "#inline_form_errors_summary" and default it to TRUE, and then allow FALSE to disable it?
Comment #68
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedChanging this to be a default true for enabling the summary is good to me. I was going to mention the current property name was too long. I don't know if
#inline_form_errors_summary
is the right name yet. It feels too verbose without actually telling us much.I know this is within a module so it should have that namespace. Ideally I see this as
provide_error_summary
.Comment #69
longwaveAs an alternative to providing this option which would also satisfy my use case: how about making the summary a Twig template?
You can either just blank out the template entirely if you don't need summaries, or provide a shorter custom message at the top of the form such as "This form has errors, please correct them below."
We could also provide template suggestions based on form ID if that level of flexibility is needed?
I suppose this suggestion relates to #2980380: Inline error messages are not using proper theming mechanisms as well.
Comment #70
Antoniya CreditAttribution: Antoniya commentedWe discussed this issue at the #3168518: Drupal Usability Meeting 2020-09-08 and a theme hook seems like a great suggestion as it would provide much better control over the summary contents.
@longwave I won't be updating the IS just yet, since others have put in a lot of work in the current patch, but I hope to see more support for improved inline_form_errors theming!
Comment #72
tsplash CreditAttribution: tsplash as a volunteer and commentedThe previous patch switched
$is_visible_element && $has_title && $has_id
to$is_visible_element || $has_title || $has_id
which caused issues with elements that only meet one of these requirements. It also did not respect #error_no_message.New patch should sort this and still checks for #disable_inline_form_errors_summary :)
Comment #73
tsplash CreditAttribution: tsplash as a volunteer and commentedTests for recent patch worked so marking as need review.
Comment #74
tsplash CreditAttribution: tsplash as a volunteer and commentedNew patch which will hide error messages in the summary for fields even if they don't have a title or ID.
Comment #75
tsplash CreditAttribution: tsplash as a volunteer and commentedMeant to include ID actually.
Comment #78
sjhuskey CreditAttribution: sjhuskey as a volunteer commented#57 works for me on 8.9.13. Thanks so much!
Comment #80
kim.pepperComment #81
Anandhi Karnan CreditAttribution: Anandhi Karnan at Srijan | A Material+ Company for Drupal India Association commentedThis may the solution for failed patch #75 , please review.
Comment #82
rahul.rahangdale CreditAttribution: rahul.rahangdale commentedPatch #81 worked for me on 9.2.3. Thanks!
Comment #83
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot for Vardot commentedPatch #81 is working with Drupal 9.2.4
Comment #85
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedFixed the fail tests for 9.3.x, Please have a look.
Comment #87
maskedjellybeanConfirmed #85 works for me in 9.2.9.
Comment #88
NuWans CreditAttribution: NuWans as a volunteer and at Niji commentedHello,
Thank for this solution.
The patch #85 works for me in 9.3.9 and 9.4.0-dev
Comment #92
dpiJust a reroll for 9.5
Comment #93
mgiffordI think that can tie to 1.4.10.
Comment #94
szantog CreditAttribution: szantog at Momentum Mozgalom commentedComment #95
rainbreaw CreditAttribution: rainbreaw as a volunteer commentedDuring the A11y office hours, we added an AI generated summary to the description. This still needs to be validated by a human, but we are hoping this might help us make it easier to address issues.
Comment #96
Diego_Mow CreditAttribution: Diego_Mow as a volunteer and at CI&T commentedPatch 92 worked in both 9.5 and 10.1.
I'm moving it to RTBC.
About AI generated summary, I reviewed it and looks pretty similar to initial summary.
It looks fine for me.
Comment #97
longwaveAs far as the API goes here I would like to repeat my comment from #67
Having said that we also have
#error_no_message
three lines above, so should we be consistent with that somehow?Comment #98
alexpottI agree with @longwave. We discussed how that would be implemented. I think we need to implement hook_element_info_alter and add
#inline_form_errors_summary
there with a default of TRUE. I think the implementation would be:Comment #99
alexpottAlso I'm really confused about why and why you'd use the setting here #disable_inline_form_errors_summary vs #disable_inline_form_errors vs #error_no_message. There's way too many double negatives here and also with the current implementation #disable_inline_form_errors_summary has to be set on the form level - but the comments and issue summary here indicate that there are still situations when it will be shown even if this is set...
We need to add docs of these three variables and where and how they can be used. And perhaps when we write better docs a good name for the new thing will be more obvious.
Comment #100
Diego_Mow CreditAttribution: Diego_Mow as a volunteer and at CI&T commentedPatch #100 goes with followed suggestion: use key #inline_form_errors_summary
Note: we also have #disable_inline_form_errors, so consistency about naming here is really broken.
My honest suggestion is that we have this issue solved since this feature is really overtime and open a task to discuss only consistency of naming for those keys.
Comment #101
alexpottNot sure why this is changing - looks like we'd be losing coverage.
Comment #103
Diego_Mow CreditAttribution: Diego_Mow as a volunteer and at CI&T commentedGood cache alexpott. This was mistakenly changed.
Adding patch 103 without this change.
Comment #105
fotispPath #103 disables summary errors on all forms.
&& $form['#inline_form_errors_summary']
should be
&& !$form['#inline_form_errors_summary']
Comment #106
_utsavsharma CreditAttribution: _utsavsharma at OpenSense Labs for DrupalFit commentedTried to address the pointer in #105.
Please review.
Comment #107
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedFixed the fail tests for 10.1.x, Please have a look.
Comment #108
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.