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:

screencast

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

Issue fork drupal-3038141

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pancho created an issue. See original summary.

Pancho’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

uzlov’s picture

Status: Active » Needs review
Issue tags: +dckyiv2019
FileSize
1.48 KB

Added small fix for logic.
We will expand machine name, when value is not empty.

joachim’s picture

Where'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.

uzlov’s picture

Check gif in description of task. It's create vocabulary.

joachim’s picture

Status: Needs review » Needs work

Ok, thanks.

I can confirm the patch fixes the issue.

+++ b/core/misc/machine-name.es6.js
@@ -46,10 +46,13 @@
+        // Let's expand machine name for edit only if we have not empty value.

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:

commit 1a62e3c66dfe91d3dd24beb6828f28243ce856fd
Author: webchick <drupal@webchick.net>
Date:   Sun May 24 20:46:41 2015 -0700

    Issue #2488884 by pixelmord, tim.plunkett, droplet: Machine name HTML5 validation fails when field is hidden

So it sounds like #2488884: Machine name HTML5 validation fails when field is hidden should be examined for the reasons for this behaviour.

uzlov’s picture

Status: Needs work » Needs review

I 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.

gettysburger’s picture

I tested the patch for #4 and it worked fine.

I was hoping to test the patch for #8 but could not find it. Thanks.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DanielVeza’s picture

Category: Bug report » Feature request
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs reroll

This qualifies as a feature request I think. It also needs a reroll against 10.1.x

pooja saraah’s picture

Attached patch against Drupal 10.1.x
Attached reroll patch
Removing the tag reroll

lauriii’s picture

Issue tags: +Field UX
lauriii’s picture

Issue tags: +Needs tests

bnjmnm made their first commit to this issue’s fork.

bnjmnm’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
2.96 KB
1.44 KB
2.43 KB

The last submitted patch, 22: 3038141-test-only.patch, failed testing. View results

bnjmnm’s picture

Didn't set things up for an interdiff, but the change was elminating the use of jQuery .val() per the eslint rules

lauriii’s picture

Issue summary: View changes
Status: Needs review » Needs work

Is 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.

hooroomoo’s picture

hooroomoo’s picture

hooroomoo’s picture

Status: Needs work » Needs review
nayana_mvr’s picture

Verified 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.

Charchil Khandelwal’s picture

Merge request !3406 tested and applied clearly on drupal 10 version,
I have added some screenshots for references.

Thanks.

lauriii’s picture

Status: Needs review » Needs work

Posted review on the MR.

hooroomoo’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Appear to be 2 open threads in the MR 3406 if those can be looked at? @lauriii

hooroomoo’s picture

Status: Needs work » Needs review

Those threads should be addressed in the MR, marking back to NR.

smustgrave’s picture

Status: Needs review » Needs work

Thanks @laurii for taking a look. Looks like there is 1 thread with an outstanding question.

hooroomoo’s picture

Status: Needs work » Needs review
dpi’s picture

There could be some crossover between this and #2662330: Machine name generation is way too slow, at least in so far as solution LOC intersection.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Confirmed 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.

bnjmnm’s picture

Issue summary: View changes

Updated issue summary. Also did a round of Screenreader/Keyboard Nav on HEAD vs this MR and confirmed there are no regressions with that experience.

lauriii’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

Posted a question in the MR.

smustgrave’s picture

Status: Needs review » Needs work

Tested 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.

bnjmnm’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change 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.

  • lauriii committed a6509130 on 10.1.x
    Issue #3038141 by hooroomoo, bnjmnm, lauriii, pooja saraah, uzlov,...

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed a650913 and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.