4

Just trying to format a Date (or any field for that matter) in LightSwitch HTML Client Preview 2.

I have tried this 'Format Pattern' field:

https://i.stack.imgur.com/kAasn.png

But it always seems to be ignored: http://i.imgur.com/PoOcD.png

I have tried a lot of different types of fields including Text, Paragraph, Custom Control, TextBox - all ignore my Format Pattern.

I have also tried creating a 'Computed Field' on the table, but it seems the Views (screens) do not get exposure to computed fields, and I cannot display them.

I found a solution where someone created 'custom' javascript binding and set the values based on binding events, but that sounds a little 'hacked up' to me. Is there a more standard way in lightswitch to accomplish formatting?

Edit: Link here.

Peanut
  • 2,126
  • 4
  • 25
  • 38

1 Answers1

1

I share the sentiment but the only way I know to format a date is using javascript. I used the following snippet to format a date to Day/Month/Year Example 31/12/2013 in a View screen called ViewTable. The column's name is StartDate and this code goes in a post_render event.

myapp.ViewTable.StartDate_postRender = function (element, contentItem) {
    contentItem.dataBind("value", function (value) {
        if (value) {
            $(element).text(moment(value).format("DD/MM/YYYY"));
        }
    });
};

This code is more complicated if you plan to use it in editable column. I suppose the code should be pretty similar to the page referred by the link you posted.

It seems we need to know JavaScript after all. Hope this helps.

PepitoSolis
  • 131
  • 1
  • 5