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

Correct way of binding a listener through markup?

3 Answers 145 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
TrentCioran
Top achievements
Rank 1
TrentCioran asked on 08 Mar 2012, 10:07 PM
Hi,

I have the next html

<select name="month" data-role="dropdownlist" data-text-field="text" data-value-field="value" data-bind="source: months, value: selectedMonth, event: { change: changeListener }" required validationMessage="Please select {0}"></select>

Unfortunatelly this doesn't take the listener, I also tried

<select name="month" data-role="dropdownlist" data-text-field="text" data-value-field="value" data-bind="source: months, value: selectedMonth, change: changeListener" required validationMessage="Please select {0}"></select>
with same results: no listener is triggered.


Am I doing something wrong?

Thanks in advance,

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Mar 2012, 08:58 AM
Hi,

 Currently the event binding does not work with Kendo Widgets. It works only with DOM elements. You can still wire the DropDownList change event like this:

<select name="month" data-change="changeListener" ... >

However the changeListener function should live in the global scope and not in the View-Model. Here is a live demo.

Could you elaborate why you need to subscribe to the change event of the DropDownList? The value binding should eliminate this need.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
TrentCioran
Top achievements
Rank 1
answered on 09 Mar 2012, 07:42 PM
Thanks for your reply Atanas, can you post the link? I think you forgot it =P.

Answering your question, I have several dropdown lists grouped in couples to represent mont/year, given the selection of the first it gives the valid selections for the second and viceversa, that's why I need these listeners.

Regards,
0
Atanas Korchev
Telerik team
answered on 12 Mar 2012, 12:18 PM
Hi,

 Indeed I forgot the link. Here it is: http://jsbin.com/elesub/edit#javascript,html 

We decided to add support for event binding via the data-bind attribute as well. "this" in the event handler will be the View-Model and the widget will be passed in the event arguments.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
TrentCioran
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
TrentCioran
Top achievements
Rank 1
Share this question
or