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

How do I add binding to a custom widget using in a template

3 Answers 93 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Scott Rakestraw
Top achievements
Rank 1
Scott Rakestraw asked on 12 Dec 2012, 07:58 PM
Please see my code here: 
http://jsfiddle.net/RzfHu/2/

I would like this custom widget do like this:
<input type="text" data-role="colorpicker" data-bind="value:BGColor"  />
But it failed saying: Uncaught TypeError: Object [object Object] has no method 'value'
So how do I add binding to this custom widget "colorpicker"?

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 13 Dec 2012, 02:07 PM
Hello Scott,

 
The value binding requires the widget to have value method. This method will be used to get/set widgets value. Consider implementing value method in your custom widget.

Kind regards,
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
Scott Rakestraw
Top achievements
Rank 1
answered on 13 Dec 2012, 02:53 PM
Hi Georgi,

Thanks for your reply. Can you show me the syntax of adding the get/set method to a custom widget? I have tried many ways, all are not working. Thx!
0
Accepted
Georgi Krustev
Telerik team
answered on 13 Dec 2012, 04:45 PM
Hello Scott,

 
As I pointed in my last reply, you need to implement value method:

value: function(value) {
    if (value !== undefined) {
         //set value
    } else {
         //return widget's value;
    }
}
How you will set the value of the jQuery widget is a developer's decision.

Kind regards,
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!
Tags
MVVM
Asked by
Scott Rakestraw
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Scott Rakestraw
Top achievements
Rank 1
Share this question
or