locked
Lightswitch HTML: dynamically change control displayName RRS feed

  • Question

  • In HTLM client javascript, is it possible to change a control's displayName/label to correspond to a different control's value? If so, how?

    Thanks,

    Bruce


    Bruce

    Wednesday, July 9, 2014 7:03 PM

Answers

  • I don't believe changing the displayName property of a contentItem at runtime will update the label text.  That would be nice, but it didn't work the last time I tried it.

    You can change the text of a label using dataBind.  The following changes the label of 'ThisControl' to the value of 'ThatProperty'

    myapp.AddEditEntity.ThisControl_postRender = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind("screen.ThatProperty", function (newValue) {
            if (!!newValue) {
                var labelDiv = $(element.parentNode).find("div.msls-label");
                labelDiv.find("label").text(newValue);
            }
        });
    };

    HTH,

    Josh

    • Proposed as answer by joshbooker Thursday, July 10, 2014 4:29 PM
    • Marked as answer by bruce demoose Thursday, July 10, 2014 5:16 PM
    Wednesday, July 9, 2014 8:13 PM

All replies

  • I don't believe changing the displayName property of a contentItem at runtime will update the label text.  That would be nice, but it didn't work the last time I tried it.

    You can change the text of a label using dataBind.  The following changes the label of 'ThisControl' to the value of 'ThatProperty'

    myapp.AddEditEntity.ThisControl_postRender = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind("screen.ThatProperty", function (newValue) {
            if (!!newValue) {
                var labelDiv = $(element.parentNode).find("div.msls-label");
                labelDiv.find("label").text(newValue);
            }
        });
    };

    HTH,

    Josh

    • Proposed as answer by joshbooker Thursday, July 10, 2014 4:29 PM
    • Marked as answer by bruce demoose Thursday, July 10, 2014 5:16 PM
    Wednesday, July 9, 2014 8:13 PM
  • Hi guys,

    You can definitely do the following in the latest VS2013 HTML client - I do this in the created event for example:

    screen.findContentItem("MyField").displayName = "My New Label";

    If you combine that with Josh's dataBind code to change it dynamically, whenever another property changes, it should really work?


    Regards, Xander. My Blog

    • Edited by novascape Thursday, July 10, 2014 4:40 AM
    Thursday, July 10, 2014 4:38 AM
  • Xander:

    Thanks for the reply, but while changing displayName in the created event works as expected, when done in Contorl_postRender via binding, the displayName value is updated but the screen label does not reflect the change.

    Bruce


    Bruce

    Thursday, July 10, 2014 1:37 PM
  • Josh:

    Works like a charm.

    Many Thanks,

    Bruce


    Bruce

    Thursday, July 10, 2014 1:49 PM
  • That is interesting that it should only work in the created event... perhaps a bug or a yet to be implemented missing feature?

    Regards, Xander. My Blog

    Thursday, July 10, 2014 10:28 PM