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].value being 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].value is 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.

Issue fork webform-3414361

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:

Comments

roderik created an issue. See original summary.

roderik’s picture

Status: Active » Needs review
StatusFileSize
new477 bytes

Let's start out with a patch file for the simple solution, while we get people's opinions...

roderik’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 3414361-webform-duplicate-remove-title.patch, failed testing. View results

roderik’s picture

Issue summary: View changes
junkuncz’s picture

Tests should be checked/adjusted? however it works for me.

junkuncz’s picture

Status: Needs work » Needs review
roderik’s picture

"Needs review" status is for a decision on approach. See "Proposed resolution" / "Remaining tasks".

jrockowitz’s picture

I 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

jrockowitz’s picture

Status: Needs review » Postponed
roderik’s picture

Thank you for that. I was unable to derive/reason whether this Core change was a bug.

dalin’s picture

Status: Postponed » Active

This issue in Drupal Core was closed as "feature, not a bug". Is there anything that we can do for this within Webform?

jrockowitz’s picture

Version: 6.2.x-dev » 6.3.x-dev

jrockowitz changed the visibility of the branch 3414361-duplicate-machine-name to hidden.

jrockowitz’s picture

Status: Active » Needs review

I think the only thing we can do override the machine name js and ensure that the webform id is syncing when duplicating a webform.

jrockowitz’s picture

I am excited to fix this very annoying issue. Please review the MR.

liam morland made their first commit to this issue’s fork.

jrockowitz’s picture

Adding the new webform/webform.admin.machine-name library to all config entity duplicate forms.

jrockowitz’s picture

Status: Needs review » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • jrockowitz committed aa8ad2b5 on 6.3.x
    Issue #3414361: UX regression / error when duplicating webform in D10.2
    

  • jrockowitz committed aa8ad2b5 on 6.x
    Issue #3414361: UX regression / error when duplicating webform in D10.2
    

Status: Fixed » Closed (fixed)

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