Can I specify a format in a binding?

4 posts, 0 answers
  1. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 10 Apr 2012 Link to this post


    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
  2. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 10 Apr 2012 Link to this post


     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: 

    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!
  3. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 10 Apr 2012 Link to this post

    that is a pitty.
    I voted!

    Regards, Jaap
  4. rlapao
    rlapao avatar
    23 posts
    Member since:
    Oct 2006

    Posted 13 May 2012 Link to this post

    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?

Back to Top