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:
- Visit /admin/people/roles/add
- Type anything and hit enter
Example forms where the problem exists
- Role add: /admin/people/roles/add
- Field add:/admin/structure/types/manage/{node_type}/fields/add-field
- Webform field add - see #3052152: Key is not automatically populated after validation failure on blank title
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.
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?
Comment | File | Size | Author |
---|---|---|---|
#4 | machine_name_required.jpg | 29.25 KB | Alan D. |
Issue fork drupal-2662330
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
Alan D. CreditAttribution: Alan D. commentedFrom #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:
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.
Comment #3
mradcliffeAs 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
Comment #4
Alan D. CreditAttribution: Alan D. commentedTwo 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.
Comment #5
Alan D. CreditAttribution: Alan D. commentedBTW, 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)
Comment #7
Soundvessel CreditAttribution: Soundvessel commentedThis 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.
Comment #10
Chi CreditAttribution: Chi commentedThe 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.
Comment #11
Alan D. CreditAttribution: Alan D. commentedComment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAjax 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.
Comment #13
Soundvessel CreditAttribution: Soundvessel commentedDon'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.
Comment #14
mradcliffeI think I understand what you wrote. I see three options in addition to continuing to provide immediate feedback to the user.
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?
Comment #17
hickok CreditAttribution: hickok commentedI just want to add here, that I have encountered the same problem.
Copy->Paste from a duplicate issue:
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. :{)
Comment #20
malcomio CreditAttribution: malcomio at Capgemini commentedComment #21
PanchoSince 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.
Comment #25
pameeela CreditAttribution: pameeela commentedClosed #3094803: Block/delay submission of "add field" form while machine name is being generated as a duplicate so adding mrweiner here for credit.
Comment #26
pameeela CreditAttribution: pameeela commentedComment #32
djdevinCould this have an option to be disabled? I have zero need for transliteration and this is incredibly annoying when building out sites.
Comment #34
bnjmnmComment #39
joachim CreditAttribution: joachim as a volunteer commentedCould 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.
Comment #40
lauriiiWe 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.
Comment #41
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedSo 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.
Comment #42
lauriiiIt 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.Comment #43
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #44
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems MR has some failures.
Comment #45
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #47
lauriiiDiscussed 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:
Comment #48
catchYes 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.).
Comment #49
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #50
bnjmnmComment #51
hooroomooA 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)
Comment #52
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #53
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor the CC failure
Comment #54
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #55
smustgrave CreditAttribution: smustgrave at Mobomo commentedTest 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.
Comment #56
catchLooks like unresolved threads in the MR.
Comment #57
smustgrave CreditAttribution: smustgrave at Mobomo commentedAh you are correct. My mistake.
Comment #58
Utkarsh_33 CreditAttribution: Utkarsh_33 at Acquia commentedComment #59
smustgrave CreditAttribution: smustgrave at Mobomo commentedAppears all threads have been answered.
Comment #60
lauriiiLooks like CI is failing on a relevant test case
Comment #61
hooroomooComment #62
smustgrave CreditAttribution: smustgrave at Mobomo commentedAll green with that change. Back to RTBC
Comment #63
catchOverall 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?
Comment #64
catchBack to needs review. If we don't need the route/controller any more my preference would be to deprecate them in this issue.
Comment #65
smustgrave CreditAttribution: smustgrave at Mobomo commentedLaurii said someone is working on this just moving it so it doesn't get re-reviewed until the changes happen.
Comment #67
tim.plunkettThis should pass now. Had to move the deprecation to the method
Comment #68
smustgrave CreditAttribution: smustgrave at Mobomo commentedAll green. Ran same test I did before and still appears to work. Moving back to RTBC.
Comment #69
lauriiiI 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 moveDrupal.behaviors.machineName.transliterate
into it's own API in future.Comment #71
lauriiiThe 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!
Comment #72
Wim LeersAWESOME 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_name
s in10.2.x
! 😊🤞Comment #73
AnybodyAlso 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:
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!
Comment #74
longwave@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.