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

Binding E-mail field to href / mailto

1 Answer 449 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 01 Oct 2012, 09:01 PM
Is there a way to bind an observable e-mail address to the href attribute of an element?  I tried the following:
<a data-bind="{attr:{href:Email},text:Email}"></a>

But of course this lacks the needed "mailto:".

I know in Knockout you can do it like this:
<a data-bind="{attr:{href:'mailto:'+Email},text:Email}"></a>

I tried that in Kendo and it failed with an "Unrecognized string" error.

What's the best way to handle this type of binding in Kendo's MVVM setup?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 04 Oct 2012, 12:27 PM
Hello Jeffrey,

Kendo MVVM does not support JavaScript bindings. To make a mailto link you should create a function in the viewModel. As an example:
var viewModel = kendo.observable({
    mail: "mail@mail.com",
    mailtoLink: function() {
        return "mailto:" + this.get("mail");
    
})
     
kendo.bind($("#example"), viewModel)
<div id="example">
    <a data-bind="attr: { href: mailtoLink }">mail</a>
</div>

A similar scenario is explained in this help topic.

Regards,
Alexander Valchev
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
Jeff
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or