"Remove item" only works on second click when more than one menu field exists on a content type.

Created on 23 October 2012, about 12 years ago
Updated 11 November 2024, 12 days ago

Looks like menu_field has been refactored quite from the version that we are using and does not include the "remove item" any more.So this may not apply to current branch of the code.

Remove item button

The remove item button only seems to work the second time it is clicked. The first time it is clicked it does not do anything.

Comparing first and second clicks of Remove item

First line is first instance of menu field
Second line is second instance of menu field

Before first click of Remove item for the first menu item:

Note: the name and id is the same for both Remove item buttons

 <input ... id="edit-field-menu-und-0-remove-button" name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea" ...>
<input ... id="edit-field-mobile-menu-und-0-remove-button" name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea" ...> 

After first click of Remove item for the first menu item:

Once, the Remove item has been clicked for a field the first time, when you click it the second time the correct action of removing the item is performed.

Note: The name is the same, but the id is different for each item

 <input ... id="edit-field-menu-und-0-remove-button"    name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea" ...>
<input ... id="edit-field-menu-und-0-remove-button--2" name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea" ...>  

You can see that names for both Content and Mobile fields are exactly the same which is a problem because when Remove item is first clicked it does not know which field to act on. However, once the AJAX call happens the first time the id for the field being clicked on is rewritten appending --2 to the id to signify a distinction between the two buttons (content & mobile). Then clicking on Remove item for the second time works.

Solution

The issue appears to be the fact that the fields have the same field name for the Remove item button. To fix this, we can add the $id_prefix (defined on line 163) to the end of the name for the Remove item option:

/sites/all/modules/contrib/field_menu.module

264 '#name' => 'menu-field-remove-' . $item['uuid'],  // Before
264 '#name' => 'menu-field-remove-' . $item['uuid'] . '-' . $id_prefix, // After 

Now the "Remove item" works correctly on the first click because it can uniquely identify the field that was clicked.

With the corrected code the field names for the Remove item button now have unique field names with the field name appended to the original name for the Remove item button.

... id="edit-field-menu-und-0-remove-button" name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea-field_menu"  ...
... id="edit-field-mobile-menu-und-0-remove-button" name="menu-field-remove-4ddb5f3e-12ed-11e2-bbcc-000c29cc69ea-field_mobile_menu" ...
πŸ› Bug report
Status

Closed: won't fix

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States alphageekboy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    This issue is about the field_menu module, not the menu_field module. There is no supported Drupal 7 version of the field_menu module.

Production build 0.71.5 2024