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

Can I specify a format in a binding?

3 Answers 576 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jaap
Top achievements
Rank 2
Jaap asked on 10 Apr 2012, 12:27 PM
Hello,

I want to bind a simple span tag to a date field. I need to specify that the date should be formatting as a shortdate, using the current culture. I know I can create a function  on my viewmodel to do the formatting and bind the span to that function.
But that feels a bit as overkill.
Can I specify the format in the data-bind itself somehow?
Something like: <span data-bind="text: {mydatefield:d}"/>

Regards, Jaap

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Apr 2012, 01:49 PM
Hi,

 No, this is not currently supported - you have to create a function which will return the formatted value. You may consider voting for this user voice item: http://kendo.uservoice.com/forums/127393-kendo-ui-feedback/suggestions/2712188-ability-to-specify-data-format-mvvm- 

Kind 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
Jaap
Top achievements
Rank 2
answered on 10 Apr 2012, 01:58 PM
that is a pitty.
I voted!

Regards, Jaap
0
rlapao
Top achievements
Rank 1
answered on 14 May 2012, 01:56 AM
Hi Atanas,

I have a similar scenario that I don't know if it is supported.
I have a kendo datasource with one field, let's say tags, that can have, or not, any tags data.

In the case that the model has no tags I want to display something like "no tags".

What I have done for now as workaround is having an extra method in the datasource model definition that is a function like
...
tags: function () { return (this.get("selectedItem").Tags === "") ? "no tags" : this.get("selectedItem").Tags); },
...

Which is very dirty, besides the fact that 'this' has different values depending if I am binding the list or a selected item.

I tried to externalize the method to a separate module and have something like:
<span id="tags" data-bind="text: Module.tags(selectedItem.Tags)"></span>

but this doesn't work, i get ther error "Mozilla error: invalid scope variables"

Is this supported?

Thanks
Tags
MVVM
Asked by
Jaap
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Jaap
Top achievements
Rank 2
rlapao
Top achievements
Rank 1
Share this question
or