lachire opened a new issue, #1618:
URL: https://github.com/apache/wicket/issues/1618

   ### Summary
   
   `Wicket.Palette.moveUpHelper` in 
`wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js`
 calls `box.trigger('focus')`, but `box` is a plain DOM `<select>` element, not 
a jQuery object. Clicking the "move up" button on an ordered `Palette` throws a 
`TypeError` and the item is never reordered.
   
   Affects the `wicket-10.x` branch and releases **10.9.0 through 10.11.0**. 
`master` is not affected (see below).
   
   ### Reproduction
   
   Render a `Palette` with `allowOrder=true`, select an item that is not 
already first, and click the up arrow.
   
   Observed in the browser console:
   
   ```
   Uncaught TypeError: a.trigger is not a function
       at Wicket.Palette.moveUpHelper (palette-ver-....js)
       at Wicket.Palette.moveUp (palette-ver-....js)
   ```
   
   The item does not move. The "move down" button works correctly.
   
   ### Cause
   
   `Wicket.Palette.moveUp` resolves the element through `Wicket.Palette.$`, 
which is `document.getElementById`:
   
   ```js
   Wicket.Palette.moveUp=function(choicesId, selectionId, recorderId) {
        var selection=Wicket.Palette.$(selectionId);
   
        if (Wicket.Palette.moveUpHelper(selection)) {
                var recorder=Wicket.Palette.$(recorderId);
                Wicket.Palette.updateRecorder(selection, recorder);
        }
   };
   ```
   
   so the `box` passed to the helper is a raw DOM node with no `trigger` method:
   
   ```js
   Wicket.Palette.moveUpHelper=function(box) {
        var dirty=false;
        for (var i=0;i<box.options.length;i++) {
                if (box.options[i].selected && i>0) {
                        if(!box.options[i-1].selected) {
                                
box.insertBefore(box.options[i],box.options[i-1]);
                                dirty=true;
                                box.trigger('focus');   // <-- TypeError
                        }
                }
        }
        return dirty;
   };
   ```
   
   The `TypeError` propagates out of the loop before `return dirty`, so 
`moveUp` never reaches `updateRecorder`. The hidden recorder input therefore 
keeps the previous order and the server never sees the move, so the DOM 
reordering that did happen is discarded on the next render. That is why the 
button appears to do nothing rather than merely failing to restore focus.
   
   `moveDownHelper` has no equivalent call, which is why "move down" is 
unaffected.
   
   ### Regression range
   
   Introduced by WICKET-7179 ("add support for jQuery 4.0.0"), commit 
7362447c83c89783d042469a04234f3a980be702 (2026-04-30), which rewrote 
`box.focus()` as `box.trigger('focus')`. Fix versions on WICKET-7179 are 11.0.0 
and 10.9.0, which matches what the published artifacts contain:
   
   | wicket-extensions | `moveUpHelper` |
   | --- | --- |
   | 7.18.0, 9.7.0, 9.21.0, 10.5.0 – 10.8.0 | `box.focus()` — unaffected |
   | 10.9.0 – 10.11.0 | `box.trigger('focus')` — broken |
   
   ### Branch status
   
   `master` regained `box.focus()` incidentally in commit 
615af3ee958379781cc9a416ce0ebd7e6ae31248 ("Add a jQuery-free implementation of 
Wicket's client-side Ajax engine", 2026-09-12), which dropped jQuery from this 
file altogether — `jQuery(recorder).trigger('change')` in `updateRecorder` 
became `Wicket.Event.fire(recorder, 'change')` in the same change.
   
   `wicket-10.x` still has the bug. Since that jQuery-removal work is unlikely 
to be backported, 10.x needs the one-line fix on its own.
   
   ### Suggested fix
   
   On `wicket-10.x`, revert the single line in `moveUpHelper`:
   
   ```diff
   -                                    box.trigger('focus');
   +                                    box.focus();
   ```
   
   Alternatively `jQuery(box).trigger('focus')` would also work, but 
`box.focus()` matches what `master` now does and avoids the jQuery dependency.
   
   I am happy to open a PR against `wicket-10.x` if that is useful.
   
   ### Environment
   
   Reported by a user on Apache Wicket 10.11.0 (via Bloomreach Experience 
Manager 16.9.2), reproduced across multiple browsers.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to