-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SelectOneMenu: Incorrect selection using Enter key and Labelname contains "Enter" #11809
Labels
Milestone
Comments
marioinfang
added
‼️ needs-triage
Issue needs triaging
🐞 defect
Bug...Something isn't working
labels
Apr 25, 2024
Fixed with monkeypatch in if (PrimeFaces.widget.SelectOneMenu) {
PrimeFaces.widget.SelectOneMenu.prototype.bindKeyEvents = function() {
var $this = this;
this.keyboardTarget.on('keydown.ui-selectonemenu', function(e) {
switch (e.key) {
case 'ArrowUp':
case 'ArrowLeft':
$this.callHandleMethod($this.highlightPrev, e);
break;
case 'ArrowDown':
case 'ArrowRight':
$this.callHandleMethod($this.highlightNext, e);
break;
case 'Enter':
$this.handleEnterKey(e);
break;
case 'Tab':
$this.handleTabKey(e);
break;
case 'Escape':
$this.handleEscapeKey(e);
break;
case ' ':
$this.handleSpaceKey(e);
break;
}
})
.on('keyup.ui-selectonemenu', function(e) {
if (PrimeFaces.utils.ignoreFilterKey(e) || !PrimeFaces.utils.isPrintableKey(e)) {
return;
}
var matchedOptions = null,
metaKey = e.metaKey || e.ctrlKey || e.altKey;
if (!metaKey) {
clearTimeout($this.searchTimer);
// #4682: check for word match
var text = $(this).val();
if (!$this.focusInput) {
$this.searchValue += e.key;
text = $this.searchValue;
}
matchedOptions = $this.matchOptions(text);
if (matchedOptions.length) {
var matchIndex = matchedOptions[0].index;
if ($this.panel.is(':hidden')) {
$this.callHandleMethod(function() {
var highlightItem = $this.items.eq(matchIndex);
$this.selectItem(highlightItem);
}, e);
} else {
var highlightItem = $this.items.eq(matchIndex);
$this.highlightItem(highlightItem);
PrimeFaces.scrollInView($this.itemsWrapper, highlightItem);
}
} else {
// #4682: check for first letter match
text = e.key.toLowerCase();
// find all options with the same first letter
matchedOptions = $this.matchOptions(text);
if (matchedOptions.length) {
$this.callHandleMethod(function() {
var selectedIndex = -1;
// is current selection one of our matches?
matchedOptions.each(function() {
var option = $(this);
var currentIndex = option[0].index;
var currentItem = $this.items.eq(currentIndex);
if (currentItem.hasClass('ui-state-highlight')) {
selectedIndex = currentIndex;
return false;
}
});
matchedOptions.each(function() {
var option = $(this);
var currentIndex = option[0].index;
var currentItem = $this.items.eq(currentIndex);
// select next item after the current selection
if (currentIndex > selectedIndex) {
if ($this.panel.is(':hidden')) {
$this.selectItem(currentItem);
} else {
$this.highlightItem(currentItem);
PrimeFaces.scrollInView($this.itemsWrapper, currentItem);
}
return false;
}
});
}, e);
}
}
$this.searchTimer = setTimeout(function() {
$this.searchValue = '';
$this.focusInput ? $this.focusInput.val('') : null;
}, 1000);
}
});
}
}; |
This was referenced Apr 25, 2024
melloware
added a commit
to melloware/primefaces
that referenced
this issue
Apr 25, 2024
melloware
added a commit
to melloware/primefaces
that referenced
this issue
Apr 25, 2024
Thanks! The monkeypatch fixes the problem. |
Thanks for testing. Fix will be in 13.0.9 |
melloware
added a commit
that referenced
this issue
Apr 25, 2024
melloware
added a commit
that referenced
this issue
Apr 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Describe the bug
If a SelectOneMenu item contains "Enter" at the beginning of a label, selecting with the Enter key does not work correctly.
The UI shows always the first Item with "Enter" in the label.
However, the correctly selected item is sent to the backend.
Reproducer
PrimefacesTest.zip
Expected behavior
If I select an item with the Enter key, the selected item should be displayed.
PrimeFaces edition
Community
PrimeFaces version
13.0.7 / 13.0.8
Theme
No response
JSF implementation
MyFaces
JSF version
3
Java version
JDK 11
Browser(s)
Chrome Version 124.0.6367.79 (Offizieller Build) (64-Bit)
The text was updated successfully, but these errors were encountered: