Problem/Motivation
When duplicating a webform whose title is equivalent to an existing machine name, we get an error on saving and have to explicitly change the machine name to something else.
See screenshot that says "Duplicate 'Contact Us' form":
- In D10.1, the prospective machine name for the new form would auto-change as we typed a new title, so if we change this to "Contact Sales, the machine name automatically changes to "contact_sales".
- In D10.2, this does not happen. The machine name stays "contact_us" and if we press "Save" immediately, this gives an error.
Cause: in #2662330: Machine name generation is way too slow, the code of machine-name.js changed.
- I cannot tell you exactly what this particular piece of code does, but it results in
$target[0].valuebeing set with a value, while it was empty just before. This does not happen in D10.1. - A little later on (line 182 in the linked version of machine-name.js),
$target[0].valueis interpreted as "the machine name was already set, so this is a pre-existing existing thing, we are not going to attach the code that changes the machine name as the user types".
Steps to reproduce
- Have an existing form with machine name "contact" and title "Contact"
- Visit the "duplicate" screen and type "Contact someone" in the title. (See that the machine name does not change.)
- Save form without doing anything else -- get error.
Note the following do not immediately reproduce the bug:
- An existing form with machine name "contact" and title "Contact Us" -- the first time.
- Reason: upon opening the duplication screen, the assigned machine name is "contact_us", which likely does not exist yet.
- If the user does not pay any attention to the machine name before saving, then they will only get an error the second time the form is duplicated -- because then the machine name "contact_us" already exists.
- A webform template -- the first time.
- In the same way, the second time that a template gets saved into a 'real' form, it will have an already-existing machine name and an unsuspecting user gets an error.
Proposed resolution
The simple solution: empty out the original title in the "duplicate" form.
This way, auto-changing the machine name is restored.
Disadvantage / possible UX regression: the user needs to completely type the new title again -- or copypaste it from the webpage title which says "Duplicate 'TEMPLATE-TITLE' form"
The more complicated solution: change code so that the JS still attaches the machine-name-auto-change behavior even though the title is empty now.
I'm mentioning this in case the simple solution is considered a big UX regression. IMHO it is less of a regression than the current situation, which can lead to inadventently saving a new webform with a totally different/unintended machine name, if a user doesn't pay attention to changing the machine name to the new title. (And users have never been taught to pay attention to this.)
Remaining tasks
Decision on whether this is a UX regression.
Review.
User interface changes
For the simple solution: the user needs to completely type the new title again in a webform that is going to be duplicated / created from a template.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3414361-webform-duplicate-remove-title.patch | 477 bytes | roderik |
| webform-duplicate.png | 85.42 KB | roderik |
Issue fork webform-3414361
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
roderikLet's start out with a patch file for the simple solution, while we get people's opinions...
Comment #3
roderikComment #5
roderikComment #6
junkunczTests should be checked/adjusted? however it works for me.
Comment #7
junkunczComment #8
roderik"Needs review" status is for a decision on approach. See "Proposed resolution" / "Remaining tasks".
Comment #9
jrockowitz commentedI think this regression is coming from Drupal core and we see if core has a fix.
Possible tickets to look at.
#3428652: Broken auto creation of machine name field
Comment #10
jrockowitz commentedThe machine name code was refactored in 10.2.x.
https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/misc/machin...
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/misc/machin...
Comment #11
jrockowitz commentedHere is the ticket created for Drupal core. #3438739: The calculated machine is not synced when the source value is defined and the machine name is empty
Comment #12
jrockowitz commentedComment #13
roderikThank you for that. I was unable to derive/reason whether this Core change was a bug.
Comment #14
dalinThis issue in Drupal Core was closed as "feature, not a bug". Is there anything that we can do for this within Webform?
Comment #15
jrockowitz commentedComment #17
jrockowitz commentedI think the only thing we can do override the machine name js and ensure that the webform id is syncing when duplicating a webform.
Comment #19
jrockowitz commentedI am excited to fix this very annoying issue. Please review the MR.
Comment #21
jrockowitz commentedAdding the new webform/webform.admin.machine-name library to all config entity duplicate forms.
Comment #24
jrockowitz commented