Problem/Motivation

Anybody typing with two hands an element with a machine name, then hitting submit will almost certainly end up with an "Machine name is required" error, or worse as a developer, a 1 or 2 character machine name, meaning you have to delete and restart again.

After the validation error has happened, the machine name field is not automatically populated from the label value.

Steps to replicate:

  1. Visit /admin/people/roles/add
  2. Type anything and hit enter

Example forms where the problem exists

I thought I saw some AJAX validation which would have explained this, but I must have been dreaming.

Dependency evaluation for transliteration.js.

1. Maintainership of the package:
Transliteration.js is not well maintained as the last major version came back in 2018.

2. Security policies of the package:
Transliteration.js has not had any reported security issues to date. The library is well documented.

3. Expected release and support cycles:
There is no mention of the release cycle.

4. Code quality:
The codebase of Transliteration.js is well written, well documented, and adheres to best practices.

5. Other dependencies it would add:
Transliteration.js has no additional dependencies beyond the basic Javascript language libraries.

Link to the repo
Readme

Proposed resolution

If AJAX, validation should happen asynchronously of the value typed.

If JavaScript, some profiling and speeding up is highly desirable ;)

Remaining tasks

--

User interface changes

None

API changes

None?

CommentFileSizeAuthor
#4 machine_name_required.jpg29.25 KBAlan D.

Issue fork drupal-2662330

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

Alan D. created an issue. See original summary.

Alan D.’s picture

From #2333053: JavaScript for #type => 'machine_name' registers key presses on 'source' slowly later, when label has spaces, special or international characters in it, it appears to be the transliteration for I18N that is causing the delay grief here, rather than a validation callback.

I wonder if it would be possible to have this as a configurable option, simple ASCII replacements or full transliteration support?

And as an aside, I wonder if it was a super-fast typer that wrote that patch:

        // Wait 300 milliseconds since the last event to update the machine name
        // i.e., after the user has stopped typing.

The average person typing should type about 200 characters per minute, or 300ms per character, so on average 50% of letters typed would trigger a call.

mradcliffe’s picture

As contrary anecdotal evidence, I have not experienced this as a touch typer. Admittedly I am not as fast as I used to be, but am still pretty quick. Perhaps this needs some metrics before making a claim about certainty.

I wonder if result would differ based on the following?

- Length of label typed
- Browser
- Typist's character per second
- Result

Alan D.’s picture

FileSize
29.25 KB

Two goes, I must have needed a slight warm up.

Role page, typed admin followed by enter.

This particular one I don't care too much about, a slight hassle, no biggie. I first noticed this when typing the role Site builder and ended up with a role with a machine name of s.

Alan D.’s picture

BTW, I did flag this as minor ;)

FYI:
Browser: Chrome
Typing speed: average, about 35 WPM. Common words phases much faster
Time to type admin: 0.972s (used http://www.typing-lessons.org/exercise_6.html to test)
System: D8 on localhost, PHP5.6, Intel i7 3.5GHz with 32GB RAM (fairly powerful system with no network overheads)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Soundvessel’s picture

This has been a serious UX issue for me because if hitting submit too quickly the full name you type doesn't get generated into a machine name. This results in incomplete machine named fields that make it difficult to know what they are and you are then stuck with them after data has been added.

Consider an easier temporary fix of disabling the submit button until AJAX has completed updating the machine name during user input.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Chi’s picture

Component: forms system » other
Category: Feature request » Bug report
Priority: Minor » Major

The generation is slow because it happens on server side. It's rather major UX issue. I wonder if we can implement it without ajax requests.

Alan D.’s picture

Version: 8.3.x-dev » 8.4.x-dev
Component: other » forms system
Priority: Major » Normal
jrockowitz’s picture

Ajax request is used "transliterate a human-readable name to a machine name."

I am not finding any javascript libraries that can do client-side transliteration.

Soundvessel’s picture

Don't worry about increasing the speed processing and returning/displaying the machine name. You can fix most of the UX issues by using/processing the value of the input on submitting instead of the last returned/displayed machine name. If you really want to force people to see the generated machine name then you can either make a confirmation screen or on input entry disable the submit button until 200ms after the generated machine name is returned and displayed.

mradcliffe’s picture

You can fix most of the UX issues by using/processing the value of the input on submitting instead of the last returned/displayed machine name.

I think I understand what you wrote. I see three options in addition to continuing to provide immediate feedback to the user.

  1. Do not use the immediate feedback as the actual input value on form submission only if manual input was not provided,
  2. disable submit until the final AJAX call is returned,
  3. or warn the user if the machine name auto generation is not yet finished on form submit

If the expectation is that we are providing an example/feedback to the user, then I think #1 works. However if it is not considered a preview, then the user's expectation is that what they see is what they get, right? And then #2 or #3 matches their expectation?

Do I understand that correctly?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hickok’s picture

I just want to add here, that I have encountered the same problem.

Copy->Paste from a duplicate issue:

I have created a new text field for Article entity content and I typed "Test text" -> and pressed Enter.
Problem is that created field had machine name: "field_t" - instead of "field_test_text". :{(

What could be a possible solution is:
Blocked submitting of form until machineNameHandler finishes with its machine name generation.

Wait time of 300ms is a lot, I can tell from my own experience. :{)

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

malcomio’s picture

Issue summary: View changes
Pancho’s picture

Since 8.3.x, the delay should be down to 300ms, if no transliteration is needed, because of #2668596: No delays update for Machine Name.
If transliteration happens, the delay however remains at 600ms, which still is a considerable UX issue.

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.

pameeela credited mrweiner.

pameeela’s picture

pameeela’s picture

Issue tags: +Bug Smash Initiative

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.

djdevin’s picture

Could this have an option to be disabled? I have zero need for transliteration and this is incredibly annoying when building out sites.

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

bnjmnm’s picture

Issue tags: +Field UX

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

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

joachim’s picture

Could the form submission be disabled until the machine name has been generated? I wouldn't say it's 'way too slow'. It's slower than someone typing fast and pressing Return quickly.
Having to wait 1-2 seconds for it to finish its work so you can submit the form is ok UX I think. It's a huge improvement on submitting the form and having a truncated machine name which then means you have to delete and start again.

lauriii’s picture

We are looking into potentially using the machine name field in #2521800: List key|label entry field is textarea, which doesn't give guidance towards the expected input which would mean that you would potentially fill out multiple machine name fields on a single page. In this case, even a few second delay could be quite jarring.

The PR from @Utkarsh_33 is trying to re-implement the machine name generation on the client side, which would mean that the machine name could be generated almost immediately, and it wouldn't depend on latency.

Utkarsh_33’s picture

So tried implementing the machine name generation at the client side using the Transliterationlibrary but the major problem while using this library is that it does not take the different languages into consideration while translating the same text.
For example the test named providerTestMachineNameController() fails when we change the langcode.

lauriii’s picture

It looks like the library does have an option for language overrides. The replace property in the option allows overriding replacement patterns for specific characters: https://github.com/dzcpy/transliteration#transliteratestr-options. It is not per language, but we should be able to implement the language aware overrides on our side. This seems worth investigating at least.

Utkarsh_33’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Seems MR has some failures.

Utkarsh_33’s picture

Issue summary: View changes

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lauriii’s picture

Discussed with @catch on Slack. It seems on principle the approach being proposed here is fine, since there's no way we could make the UX similar using the ajax based architecture. @catch hasn't had a chance to take a look at the library, but he didn't raise any concerns so far. The issue seemed low risk since we could always fallback to the ajax based approach if something goes wrong.

He had two questions which we could answer to by providing some additional test coverage:

Whether/how this works with non-latin characters like CJK, arabic, persian vs. the PHP implementation. Would be good to add one or two to the test coverage.

And also whether there's any chance the library creates an invalid machine name that would fail the PHP validation (seems like not though).

catch’s picture

Yes this seems like a good approach to me - it's just a helper that you can override, and there's no way we can make the speed of AJAX match not having AJAX at all. We also don't do any AJAX validation here afaik, just transliteration, so not losing anything there (checking for duplicates etc.).

Utkarsh_33’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Needs work
hooroomoo’s picture

A couple of small things, and it looks like there still needs to be test cases added to core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php from \Drupal\Tests\Component\Transliteration\PhpTransliterationTest::testPhpTransliteration (one of the unresolved threads)

Utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

For the CC failure

Utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Test MR but going to admin/people/roles/add typing something real fast and pressing enter. New package also appears to have gone through, at least first round, of approval.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Looks like unresolved threads in the MR.

smustgrave’s picture

Status: Needs review » Needs work

Ah you are correct. My mistake.

Utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

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

Appears all threads have been answered.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Looks like CI is failing on a relevant test case

hooroomoo’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All green with that change. Back to RTBC

catch’s picture

Overall this looks encouraging.

Is the AJAX transliteration controller unused now, and could we deprecate both the controller and the route for removal in 11.x?

catch’s picture

Status: Reviewed & tested by the community » Needs review

Back to needs review. If we don't need the route/controller any more my preference would be to deprecate them in this issue.

smustgrave’s picture

Status: Needs review » Needs work

Laurii said someone is working on this just moving it so it doesn't get re-reviewed until the changes happen.

tim.plunkett made their first commit to this issue’s fork.

tim.plunkett’s picture

Status: Needs work » Needs review

This should pass now. Had to move the deprecation to the method

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All green. Ran same test I did before and still appears to work. Moving back to RTBC.

lauriii’s picture

I updated the deprecation message to deprecate this in 10.2.0 since I think it's too late to backport this to 10.1.x. I also removed the mention of Drupal.behaviors.machineName.transliterate to avoid recommending something that isn't necessarily intended as an API. We may want to ask the framework managers if we want to move Drupal.behaviors.machineName.transliterate into it's own API in future.

  • lauriii committed 570710ad on 11.x
    Issue #2662330 by Utkarsh_33, lauriii, hooroomoo, bnjmnm, tim.plunkett,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

The previous commits revert few changes that were out of scope and not strictly required for the fix. I opened #3367420: Generate machine names even faster as a follow-up.

Confirmed with @catch on Slack that he's fine with the library addition since that wasn't explicitly confirmed on the issue.

Committed 570710a and pushed to 11.x. Thanks!

Wim Leers’s picture

AWESOME work here!

You know what would be a great complementary commit?

#2920678: Add config validation for the allowed characters of machine names

Then we'd have solved all fundamental problems with machine_names in 10.2.x! 😊🤞

Anybody’s picture

Also note #1643386: Strip useless "_" at beginning and end of JS-transliterated machine names which was affected by these changes.

@laurii:
This was committed to 11.x and marked fixed, but the deprecation message says:

* @deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no

Doesn't this need to be backported / committed to 10.2.x then, or am I missing something? Or is the comment wrong?

Just wanted to ensure it's not forgotten... :) Thanks!

longwave’s picture

@Anybody see https://www.drupal.org/about/core/blog/new-drupal-core-branching-scheme-... - 10.2.x will eventually be branched from 11.x, the branch is not open yet.

Status: Fixed » Closed (fixed)

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