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

How do I get the keyup event of a ComboBox?

2 Answers 499 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 22 Mar 2013, 07:23 PM
The ComboBox is done in Razor:
@Html.Kendo().ComboBox()
  .Name(id)
  .Filter("contains")
  .DataTextField("ChoiceValue").DataValueField("ChoiceValue")
  .BindTo(inputs.Choices)
  .HtmlAttributes(new { @class = classText, data_validation = inputs.Validation })
If I use inline javascript, it works:
var input = $('#id').data('kendoComboBox').input;
input.bind({ keyup: function () { doStuff('test'); } });
But if I reference a separate file, I get this error: Uncaught TypeError: Cannot read property 'input' of undefined

How can I get this to work using a separate .js file?


2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Mar 2013, 05:29 PM
Hello,

May be you are trying to access input element before it was created that's why you get null/undefined in varibale 'input'. (because first js file loaded and executed before creating the input element).

Page life cycle in Kendo ui Grid
1.  Load the JS File  (because we generally add JS file reference in HEAD Tag)
2.  Create Input element
3.  Convert this input into kendo ui combobox.

Thanks,
Jayesh Goyani
0
Brent
Top achievements
Rank 1
answered on 25 Mar 2013, 01:41 PM

Yes, I see that you are correct. Thanks for the info on the page life cycle.

I was able to get the keyup event like this:

$('input.k-input.comboBox').each(function () {
    $(this).keyup(function () { });
});

It was confusing to me that the same inline js code used in HTML cannot be used when imported from a separate .js file.

Tags
ComboBox
Asked by
Brent
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Brent
Top achievements
Rank 1
Share this question
or