Wednesday, 26 March 2014

Format date on textbox in Lightswitch HTML client

The HTML client for Ligthswitch is nice, except that not everything is that easy to obtain as in the Silverlight version. So is formatting dates on 'view' screens. Despite setting it at the entity in the 'Server' part of the project, it doesn't show up on the HTML output.
Solution:
Add a 'postRender' script to the date field(s) you like to format.

  • Therefore, go to the (view)screen where you like to format the date.
  • Select the field which shows a date. Let say 'StartDate'.
  • Click on 'Write code' on top of the window and select 'StartDate_postRender'.
  • Add the following piece of code:

myapp.ViewProject.StartDate_postRender = function (element, contentItem) {
    // Write code here.
    contentItem.dataBind("value", function (value) {
        if (value) {
            $(element).text(value.format("dd-MM-yyyy"));
        }
    })
};


Done.

1 comment:

valwriting service said...

It's really productive, you started to blog solutions of your daily problems... gives me an idea of my own!! Also what if the same problem occurs with the windows?