So this one I found really helpful, and a special thanks to Heinrich Wendel from the Microsoft LightSwitch team for helping me out on this. I had been really struggling to make calculated fields work in the beta of the new HTML5 client for LightSwitch since I don't know JavaScript nearly as well as I know C#. I had tried any number of ways to do this, but in the end, it ended up being a few simple lines of JavaScript code that anyone can easily add and use for their project.
First I add a simple table to the project with two values, Value1 and Value2 -
Then I create an add/edit screen plus a local property to show the total and add this code to the postRender Method
myapp.Table1ItemDetail.Property1_postRender = function (element, contentItem) { // Write code here. contentItem.dataBind("screen.Table1Item.ValueOne", function (newValue) { contentItem.screen.Property1 =
contentItem.screen.Table1Item.ValueOne + contentItem.screen.Table1Item.ValueTwo;
});
contentItem.dataBind("screen.Table1Item.ValueTwo", function (newValue) {
contentItem.screen.Property1 = contentItem.screen.Table1Item.ValueOne + contentItem.screen.Table1Item.ValueTwo;
});
};
And ta-da! It updates the totals as I change the numbers! No postback needed!
This was too easy, so thanks again Heinrich for all your help! Maybe that #SaveMeJaySchmelzer hashtag worked after all. :)
