I've got an Autocomplete control on the page that accepts multiple values (using VisualMode). FilterType is set to "contains".
If the user wants to add a new item, but it is a substring of an existing item, they are not given the option to "Add New".
Using the code below, try to enter "Apple".
Result: The user must choose either "Green Apple" or "Red Apple", they can't add a new item, "Apple".
Expect: There should be an additional item, "Apple (Add New)" available for the user to choose.
How can I get the "Apple (Add New)" item to show up?
Code below is intended for https://jsplayground.syncfusion.com (https://jsplayground.syncfusion.com/x54lyihu)
<!doctype html>
<html>
<head>
<title>Essential Studio for JavaScript : Autocomplete Default</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8" />
<link rel='nofollow' href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<link rel='nofollow' href="//cdn.syncfusion.com/17.1.0.38/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
<link rel='nofollow' href="17.1.0.38/themes/web/content/default.css" rel="stylesheet" />
<link rel='nofollow' href="17.1.0.38/themes/web/content/default-responsive.css" rel="stylesheet" />
<script type="text/javascript" src="//cdn.syncfusion.com/js/assets/external/jquery-1.11.3.min.js"></script>
<script src="//cdn.syncfusion.com/js/assets/external/jquery.easing.1.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="//cdn.syncfusion.com/17.1.0.38/js/web/ej.web.all.min.js"></script>
<script src="17.1.0.38/scripts/web/properties.js" type="text/javascript"></script>
</head>
<body>
<div class="content-container-fluid">
<div class="row">
<div class="cols-sample-area">
<div class="frame">
<div class="control">
<input type="text" id="selectVeg" />
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" class="jsScript">
$(function () {
var vegList = [
"Green Apple", "Red Apple"
];
$('#selectVeg').ejAutocomplete({
allowAddNew: true,
multiSelectMode: ej.MultiSelectMode.VisualMode,
width: "100%",
watermarkText: "Select a vegetable",
dataSource: vegList,
enableAutoFill : false,
filterType: ej.filterType.Contains
});
});
</script>
</body>
</html>
This is targetting Essential Studio 17.1.0.38. Not sure why this is posting into the Javascript - EJ 2 forum.
That's definitely an improvement.
Couple of issues.
|
if(this._selectedItems.indexOf(this.element.val()) == -1) this.suggestionListItems.push(this.element.val() + this._addNewTemplate); |
|
ej.Autocomplete.prototype. _showSuggestionList = function (e) {
var sugList, newText;
if(this.model.loadOnDemand && $('body').find(this.suggestionList).length == 0)
this._renderPopup();
this.suggestionListItems = this.model.enableDistinct ? ej.dataUtil.distinct(this.suggestionListItems, (typeof this.suggestionListItems[0] != "object" ? "" : (this.model.fields && this.model.fields.text) ? this.model.fields["text"] : "text"), true) : this.suggestionListItems;
. . . . . . . .
for(var i=0; i< $(this.suggestionList).find(".e-ul li").length ; i++)
{
sugList = $(this.suggestionList).find(".e-ul li")[i].textContent;
if(sugList.indexOf("Add New") != -1)
newText = sugList.replace(this._addNewTemplate, "")
if(this.suggestionListItems[0] && this.suggestionListItems[0].toLowerCase() == this.element[0].value && (this.suggestionListItems[1] && this.suggestionListItems[1].indexOf(this._addNewTemplate)))
//check whether the first item matches the search text, and the popup has add new template.
{
if(this.suggestionListItems[1].replace(this._addNewTemplate,"") == this.suggestionListItems[0].toLowerCase())
//check whether the first and add new text are same.
{
this.suggestionListItems.pop() //remove the new text
}
}
}
if ((ej.isNullOrUndefined(newText)) && !this.noresult || this.model.showEmptyResultText )
this._generateSuggestionList(e);
}; |