Problem/Motivation
I've always been wondering why failing validation on submit expands the machine name field, forcing the user to manually enter a machine name:
Sure, it's a bit stupid to hit "submit" omitting the label field, but it may happen. We still shouldn't punish the user, and should keep automatic machine name generation in place.
Steps to reproduce
Proposed resolution
Currently, the addition of the JS facilitated machine name generation is bypassed for any machine-name field that has an error.
Fix this by bypassing machine name generation IF it has an error AND the field is not empty. Empty fields will still get JS facilitated machine name generation as empty means there's nothing wrong with the field content, it simply doesn't exist yet.
This also requires removing the "required" attribute when the machine name field is hidden to ensure clientside validation does not attempt to focus it if it is empty - validation sufficiently does what is necessary with the visible field when empty.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#31 | 1-before-patch.png | 36.24 KB | Charchil Khandelwal |
#31 | 2-before-patch.png | 36.54 KB | Charchil Khandelwal |
#31 | 1-after-patch.png | 32.04 KB | Charchil Khandelwal |
#31 | 2-after-patch.png | 32.18 KB | Charchil Khandelwal |
#30 | 3038141-after-patch.mov | 1.41 MB | nayana_mvr |
Issue fork drupal-3038141
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:
- 3038141-machine-name-field compare
- 3038141-machine changes, plain diff MR !3406
Comments
Comment #2
PanchoComment #4
uzlov CreditAttribution: uzlov at Skilld commentedAdded small fix for logic.
We will expand machine name, when value is not empty.
Comment #5
joachim CreditAttribution: joachim as a volunteer commentedWhere's the best admin page to test this on? I can't get a validation error on the node type create page, for instance, as leaving a form element blank produces a pop-up error.
Comment #6
uzlov CreditAttribution: uzlov at Skilld commentedCheck gif in description of task. It's create vocabulary.
Comment #7
joachim CreditAttribution: joachim as a volunteer commentedOk, thanks.
I can confirm the patch fixes the issue.
I don't really understand the comment.
Also, the edit button this function handles disappears whenever the main name field is empty.
I think the correct fix would rather be to remove this call to clickEditHandler() further down:
$target.on('invalid', eventData, clickEditHandler);
That's calling the function that expands the machine name element whenever the main name field is invalid.
That's the source of this behaviour.
Though it does make me wonder whether this behaviour is by design, since there's code that very specifically does this. Git blame says:
So it sounds like #2488884: Machine name HTML5 validation fails when field is hidden should be examined for the reasons for this behaviour.
Comment #8
uzlov CreditAttribution: uzlov at Skilld commentedI guess, we can't just remove
$target.on('invalid', eventData, clickEditHandler);
User should have input of machine name, when machine name is "invalid" (for example, if name already exist).
I just added fix, wich change the logic
>> // Let's expand machine name for edit only if we have not empty value.
if "invalid" = empty, because user still not added name of vocabulary, we will don't show input for edit machine name.
Comment #9
gettysburger CreditAttribution: gettysburger commentedI tested the patch for #4 and it worked fine.
I was hoping to test the patch for #8 but could not find it. Thanks.
Comment #17
DanielVezaThis qualifies as a feature request I think. It also needs a reroll against 10.1.x
Comment #18
pooja saraah CreditAttribution: pooja saraah at Material for Drupal India Association commentedAttached patch against Drupal 10.1.x
Attached reroll patch
Removing the tag reroll
Comment #19
lauriiiComment #20
lauriiiComment #22
bnjmnmComment #24
bnjmnmDidn't set things up for an interdiff, but the change was elminating the use of jQuery .val() per the eslint rules
Comment #25
lauriiiIs this still addressing the same use case? It looks like the new approach in #22 would add stricter measures to when the machine name field should be invisible, rather than loosening those requirements. The use case in the issue summary seems to be that user clicks submit, but the form isn't actually submitted because of HTML 5 validation. This shouldn't result in the machine name field being revealed when the field for a human readable value is empty.
Comment #26
hooroomooComment #27
hooroomooComment #29
hooroomooComment #30
nayana_mvr CreditAttribution: nayana_mvr at Material commentedVerified MR!3406 and tested it on Drupal version 10.1.x. The patch works fine and I have added the before and after screen recordings for reference.
Comment #31
Charchil Khandelwal CreditAttribution: Charchil Khandelwal at Dotsquares Ltd. commentedMerge request !3406 tested and applied clearly on drupal 10 version,
I have added some screenshots for references.
Thanks.
Comment #32
lauriiiPosted review on the MR.
Comment #33
hooroomooComment #34
smustgrave CreditAttribution: smustgrave at Mobomo commentedAppear to be 2 open threads in the MR 3406 if those can be looked at? @lauriii
Comment #35
hooroomooThose threads should be addressed in the MR, marking back to NR.
Comment #36
smustgrave CreditAttribution: smustgrave at Mobomo commentedThanks @laurii for taking a look. Looks like there is 1 thread with an outstanding question.
Comment #37
hooroomooComment #38
dpiThere could be some crossover between this and #2662330: Machine name generation is way too slow, at least in so far as solution LOC intersection.
Comment #39
smustgrave CreditAttribution: smustgrave at Mobomo commentedConfirmed with the MR the machine name doesn't appear for validation error.
Going to mark this but this may get sent back for issue summary update. proposed solution could be written out.
Comment #40
bnjmnmUpdated issue summary. Also did a round of Screenreader/Keyboard Nav on HEAD vs this MR and confirmed there are no regressions with that experience.
Comment #41
lauriiiPosted a question in the MR.
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedTested locally and the fix still works. Ran the test "testMachineName" and it should still be green too
Can someone remove that require line from machine-name.js
Don't want to take myself out of the review role.
Comment #43
bnjmnmComment #44
smustgrave CreditAttribution: smustgrave at Mobomo commentedChange looks good and functions correctly.
Followed the steps of the issue summary.
Went to create a vocabulary
Clicked save (without filling anything in)
Machine name filed still does not appear.
Comment #47
lauriiiCommitted a650913 and pushed to 10.1.x. Thanks!