This is a migrated thread and some comments may be shown as answers.

Suggestion about "select" event

4 Answers 119 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Jeffrey
Top achievements
Rank 1
Jeffrey asked on 18 Jan 2012, 07:36 AM
In my cases, I need to assign additional field's value when user select a result from the hint list.  For example, 
<script>
    $(function () {
        $("#tCode").kendoAutoComplete({
            dataTextField: "Code",
            dataSource: [ { Code:"10", Name:"Jeffrey" }, { Code:"11", Name:"Jack" }]
        });
    });
</script>
<input id="tCode" /><input id="tName" />

When "10" is selected, tName's value should be "Jeffrey", when "11" is selected, tName's value should be "Jack".

Here is my suggestion: adding a select event in kendo.autocomplete.js
if (separator) {
    text = replaceWordAtCaret(caretPosition(that.element[0]), that.value(), text, separator);
}
//2012-01-18 by Jeffrey Lee
//when item is selected, trigger select event with data as argument
if ($.isFunction(that.options.select))
    that.options.select(data);
 
that.value(text);
that.current(li.addClass(SELECTED));

After adding the "select" event, it's quite easy to  implement the "field-linking" by add select parameter in options:
<script>
    $(function () {
        $("#tCode").kendoAutoComplete({
            dataTextField: "Code",
            dataSource: [{ Code: "10", Name: "Jeffrey" }, { Code: "11", Name: "Jack"}],
            //new "select" event triggered when hint item is selected
            select: function (data) { $("#tName").val(data.Name); }
        });
    });
</script>
<input id="tCode" /><input id="tName" />

Any feedback is welcome.

4 Answers, 1 is accepted

Sort by
0
Brian Vallelunga
Top achievements
Rank 1
answered on 02 Feb 2012, 06:00 PM
I would love this. I'm doing something very similar to you and this would be very helpful.
0
Vaughan
Top achievements
Rank 1
answered on 03 Feb 2012, 03:38 AM
I've also tried your suggestion, it's exactly what I needed. Thanks!
Is there any chance this can be rolled into the offical code?
0
Georgi Krustev
Telerik team
answered on 03 Feb 2012, 10:04 AM
Hello,

 
I will suggest you open User Voice item on this matter. Thus more people can vote for it.

Greetings,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jeffrey
Top achievements
Rank 1
answered on 04 Feb 2012, 08:32 AM
Georgi, thanks for your information, I have posted the idea in User Voice.
Tags
AutoComplete
Asked by
Jeffrey
Top achievements
Rank 1
Answers by
Brian Vallelunga
Top achievements
Rank 1
Vaughan
Top achievements
Rank 1
Georgi Krustev
Telerik team
Jeffrey
Top achievements
Rank 1
Share this question
or