Skip to content

Bind the menu item form widget so its AJAX handlers can run - #57

Open
AIC-BV wants to merge 1 commit into
wintercms:mainfrom
AIC-BV:fix/menu-item-editor-widget-binding
Open

Bind the menu item form widget so its AJAX handlers can run#57
AIC-BV wants to merge 1 commit into
wintercms:mainfrom
AIC-BV:fix/menu-item-editor-widget-binding

Conversation

@AIC-BV

@AIC-BV AIC-BV commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Follow-up on #55, reported by @mjauvin: locale switching works now, but copying a value from another locale in the menu item editor throws.

Any AJAX handler belonging to a widget inside the Static Menus item editor popup fails with "A widget with class name 'formMenu<hash>ItemsMenuItemTitle' has not been bound to the controller". With Winter.Translate installed that takes out the ML controls' copy-from-locale and auto-translate handlers on title and url. Not a regression from #55 — that fix just got people far enough to hit it.

Two reasons the widget is never bound:

  1. MenuItems::prepareVars() only runs from render(), so on an AJAX request the nested item form is never made. Fixed by making it in init() and binding it there, as Backend\FormWidgets\Repeater already does for its items.
  2. The popup is a detached modal outside the editor's form, so requests arrive without formWidgetAlias / objectType / objectPath / theme and Index::index() skips bindFormWidgetToController(). Fixed by cloning those inputs into the popup form.

Verified on Winter 1.2 / PHP 8.4 with Winter.Translate dev-main: the copy popup opens and a Google-backed copy ennl-NL lands correctly. Locale switching, onGetMenuItemTypeInfo, Apply, saving, and a new unsaved menu (empty objectPath) all still work.

Summary by CodeRabbit

  • Bug Fixes
    • Improved menu-item editing by preserving the surrounding form context when opening the popup.
    • Enhanced form widget initialization and reuse for more consistent menu-item editing behavior.

Any handler belonging to a widget inside the menu item editor popup fails with
"A widget with class name formMenu<hash>ItemsMenuItemTitle has not been bound to
the controller". With Winter.Translate installed that makes the ML controls'
copy-from-locale and auto-translate handlers unusable on a static menu item.

Two things kept the widget from ever being bound:

The item form widget was made in prepareVars(), which only runs from render().
On an AJAX request Form::defineFormFields() binds the menuitems widget itself
but never reaches the nested item form, so the widgets that Winter.Translate
swaps in for `title` and `url` do not exist server-side. Make it on init() and
bind it there, the way Backend\FormWidgets\Repeater already does for its items.

The popup is a detached modal outside the editor's own form, so its requests
reached the controller without formWidgetAlias / objectType / objectPath /
theme. Index::index() gates bindFormWidgetToController() on those, so nothing
was rebuilt at all. Clone them into the popup form when it opens.

Reported by @mjauvin as a follow-up on wintercms#55.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: aa2814da-56ea-4520-a9df-479f144ac703

📥 Commits

Reviewing files that changed from the base of the PR and between db35509 and 4e3f506.

📒 Files selected for processing (2)
  • formwidgets/MenuItems.php
  • formwidgets/menuitems/assets/js/menu-items-editor.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The change caches the menu item form widget during initialization and reuses it when preparing variables. The widget receives a new MenuItem model and controller binding. The menu-item editor also copies form and object context fields into the popup form.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 4e3f5

The change binds menu item form widgets and preserves the required popup request context so AJAX locale and editor actions can run; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: binding the menu item form widget so its AJAX handlers can run.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mjauvin mjauvin self-assigned this Aug 25, 2026
@mjauvin

mjauvin commented Aug 25, 2026

Copy link
Copy Markdown
Member

Tested as a working solution.

@LukeTowers any objection for this fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants