-
Notifications
You must be signed in to change notification settings - Fork 754
-
Notifications
You must be signed in to change notification settings - Fork 754
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
Autocomplete: forceselection="false" no longer working since primefaces release 10.0.1 #8006
Labels
Milestone
Comments
MonkeyPatch: if (PrimeFaces.widget.AutoComplete) {
PrimeFaces.widget.AutoComplete.prototype.bindKeyEvents = function() {
var $this = this;
// GitHub #6711 use DOM if non-CSP and JQ event if CSP
var originalOnchange = this.input.prop('onchange');
if (!originalOnchange && this.input[0]) {
var events = $._data(this.input[0], "events");
if (events.change) {
originalOnchange = events.change[0].handler;
}
}
this.cfg.onChange = originalOnchange;
if (originalOnchange) {
this.input.prop('onchange', null).off('change');
}
if (this.cfg.queryEvent !== 'enter') {
this.input.on('input propertychange', function(e) {
$this.processKeyEvent(e);
});
}
this.input.on('keyup.autoComplete', function(e) {
var keyCode = $.ui.keyCode,
key = e.which;
if (PrimeFaces.env.isIE(9) && (key === keyCode.BACKSPACE || key === keyCode.DELETE)) {
$this.processKeyEvent(e);
}
if ($this.cfg.queryEvent === 'enter' && (key === keyCode.ENTER)) {
if ($this.itemSelectedWithEnter)
$this.itemSelectedWithEnter = false;
else
$this.search($this.input.val());
}
if ($this.panel.is(':visible')) {
if (key === keyCode.ESCAPE) {
$this.hide();
} else if (key === keyCode.UP || key === keyCode.DOWN) {
var highlightedItem = $this.items.filter('.ui-state-highlight');
if (highlightedItem.length) {
$this.displayAriaStatus(highlightedItem.data('item-label'));
}
}
}
$this.checkMatchedItem = true;
$this.isTabPressed = false;
}).on('keydown.autoComplete', function(e) {
var keyCode = $.ui.keyCode;
$this.suppressInput = false;
if ($this.panel.is(':visible')) {
var highlightedItem = $this.items.filter('.ui-state-highlight');
switch (e.which) {
case keyCode.UP:
var prev = highlightedItem.length == 0 ? $this.items.eq(0) : highlightedItem.prevAll('.ui-autocomplete-item:first');
if (prev.length == 1) {
highlightedItem.removeClass('ui-state-highlight');
prev.addClass('ui-state-highlight');
if ($this.cfg.scrollHeight) {
PrimeFaces.scrollInView($this.panel, prev);
}
if ($this.cfg.itemtip) {
$this.showItemtip(prev);
}
}
e.preventDefault();
break;
case keyCode.DOWN:
var next = highlightedItem.length == 0 ? $this.items.eq(0) : highlightedItem.nextAll('.ui-autocomplete-item:first');
if (next.length == 1) {
highlightedItem.removeClass('ui-state-highlight');
next.addClass('ui-state-highlight');
if ($this.cfg.scrollHeight) {
PrimeFaces.scrollInView($this.panel, next);
}
if ($this.cfg.itemtip) {
$this.showItemtip(next);
}
}
e.preventDefault();
break;
case keyCode.ENTER:
if ($this.timeout) {
$this.deleteTimeout();
}
if (highlightedItem.length > 0) {
$this.preventInputChangeEvent = true;
highlightedItem.trigger("click");
$this.itemSelectedWithEnter = true;
}
e.preventDefault();
e.stopPropagation();
break;
case 18: //keyCode.ALT:
case 224:
break;
case keyCode.TAB:
if (highlightedItem.length && $this.cfg.autoSelection) {
highlightedItem.trigger('click');
} else {
$this.hide();
if ($this.timeout) {
$this.deleteTimeout();
}
}
$this.isTabPressed = true;
break;
}
} else {
switch (e.which) {
case keyCode.TAB:
if ($this.timeout) {
$this.deleteTimeout();
}
$this.isTabPressed = true;
break;
case keyCode.ENTER:
var itemValue = $(this).val();
var valid = true;
if ($this.cfg.queryEvent === 'enter' || ($this.timeout > 0) || $this.querying) {
e.preventDefault();
}
if ($this.cfg.queryEvent !== 'enter') {
valid = $this.isValid(itemValue, true);
if (!$this.cfg.forceSelection) {
valid = true;
}
}
if ($this.cfg.multiple && itemValue && valid) {
$this.addItem(itemValue);
e.preventDefault();
e.stopPropagation();
}
break;
case keyCode.BACKSPACE:
if ($this.cfg.multiple && !$this.input.val().length) {
if (e.metaKey || e.ctrlKey || e.shiftKey) {
$this.removeAllItems();
} else {
$this.removeItem($(this).parent().prev());
}
e.preventDefault();
}
break;
};
}
}).on('paste.autoComplete', function() {
$this.suppressInput = false;
$this.checkMatchedItem = true;
}).on('change.autoComplete', function(e) {
var value = e.currentTarget.value,
valid = $this.isValid(value);
if ($this.cfg.forceSelection && $this.currentInputValue === '' && !valid) {
$this.preventInputChangeEvent = true;
}
if ($this.cfg.onChange && !$this.preventInputChangeEvent) {
$this.cfg.onChange.call(this);
}
$this.currentInputValue = $this.cfg.forceSelection && !valid ? '' : value;
$this.preventInputChangeEvent = false;
});
}
} |
melloware
added
workaround
A workaround has been provided
LTS-PORT
The fix can be ported to LTS versions
labels
Oct 22, 2021
melloware
added a commit
to melloware/primefaces
that referenced
this issue
Oct 22, 2021
tandraschko
pushed a commit
that referenced
this issue
Oct 23, 2021
Thank you so much for fixing this so quickly! |
You can use the MonkeyPatch for now but i marked it with "elite" label so maybe PrimeTek will pick it up and put it in 10.0.8. |
mertsincan
added
10.0.12
and removed
LTS-PORT
The fix can be ported to LTS versions
labels
Apr 29, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Describe the defect
The autocomplete component with forceselection="false" doesn't add a new value (which is not on the suggestion list) after enter key is fired.
This worked with 10.0.0 but stopped working since 10.0.1.
Looks like this was the issue introduced in 10.0.1: #7211
Reproducer
I used the example code from the showcase:
https://www.primefaces.org/showcase/ui/input/autoComplete.xhtml
Only change I did was setting forceSelection="false".
Environment:
To Reproduce
Starting with release 10.0.1 we see a changed behaviour. When we enter a new value (which is not on the sugestion list) and hit 'enter' key -> nothing happens
Expected behavior
With release 10.0.0 it worked fine, we could add values from suggestion list and also new values could be entered (like 'aaa', 'bbb', ...):
This defect is related to https://forum.primefaces.org/viewtopic.php?f=3&t=69186
The text was updated successfully, but these errors were encountered: