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

How can i bind the text of a button - or anchor - to a viewmodel?

3 Answers 637 Views
Button (Mobile)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 28 Aug 2013, 01:07 PM
To dynamically change the language of my application i' trying to use databinding to a viewmodel. It works great on labels and simple texts, but when i bind a button with e.g.

<a data-role="button" data-bind="text: i18n.connect" data-click="app.connectClicked">TEST</a>

I get an error message:
The text binding is not supported by the Button widget

Is there a workaround for this?

TIA
Peter





3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 29 Aug 2013, 10:44 AM
Hello Peter,

Such binding is not supported out of the box with Kendo UI. However using a custom binder you can achieve such functionality. Please check this example of a possible implementation:

http://jsbin.com/EKOyEqI/3/edit

If you want to read more about custom binding, please follow this link:

http://docs.kendoui.com/getting-started/framework/mvvm/bindings/custom

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Henri
Top achievements
Rank 1
answered on 04 May 2017, 03:59 PM

This is an old question, but I've solved this by binding an inner <span> element instead of the <a> directly

<a data-role="button"><span data-bind="text: blabla"></span></a>

Does not seem necessary to make a "custom binder", correct?

 

 

0
Ivan Zhekov
Telerik team
answered on 08 May 2017, 07:27 AM
Henri,

you are still binding the text, but not to a viewmodel i.e. you can't dynamically change the text after you've set it.

Still, if this way of binding works for you, then you don't need the custom binder.

Regards,
Ivan Zhekov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Button (Mobile)
Asked by
Peter
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Henri
Top achievements
Rank 1
Ivan Zhekov
Telerik team
Share this question
or