Im using telerik auto complete textbox.
when i pastes a semicolon-separated list of entries into RadAutoCompleteBox,
and on TAB press it returns only last semicolon seperated value into token.
How to get all semicolon-separated value in to separate tokan?
Thank You
Zakir
2 Answers, 1 is accepted
0
Dimitar
Telerik team
answered on 05 Sep 2014, 02:57 PM
Hi Zakir,
In order to create RadAutoCompleteBox tokens on pasting a semicolon-separated list of entries, you can use the RadAutoCompleteBox OnClientLoad event to register a handler for the "paste" event. This handler should parse the text and create entries. This feature can be achieved with the following javascript:
var $ = $telerik.$;
function OnClientLoad(sender) {
$(".racInput").on("paste", function (e) {
var $this = $(this);
setTimeout(function () { //break the callstack to let the event finish
var text = $this.val();
var lastChar = text.charAt(text.length - 1);
var myText = text;
if (lastChar === ";") {
var myText = text.substr(0, text.length - 1);
}
var array = myText.split(';')
for (var i = 0; i < array.length; i++) {
var currEntryText = array[i];
var entry = new Telerik.Web.UI.AutoCompleteBoxEntry();
entry.set_text(currEntryText);
sender.get_entries().add(entry);
}
}, 0);
})
}
In the example above, we have covered the cases when the list pasted ends with and without a delimiter.
You can modify the text processing part of the script to cover the use cases relevant for your scenarios.
Regards,
Dimitar
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.