locked
LightSwitch HTML - Validation works, but no message displayed RRS feed

  • Question

  • Hi,

    I have a LightSwitch HTML app that is using an external SQL server as the data source. Because of this all of the Validation properties are greyed out, such as Maximum and Minimum on number fields. So I tried to use Custom Validation:

    partial void MYAmount_Validate(EntityValidationResultsBuilder results)

            {

                if (this.MYAmount < 0)

                {

                    results.AddPropertyError("The Amount cannot be negative");

                }

    This does prevent the data from saving, but no message is displayed for the user. Is there something else I need to do for a message to display/popup saying what caused the save to fail?

    Also I am using a custom save function, is this causing my issue?:

    myapp.commitChanges().then(function () {

            screen.vwView1.refresh();

            screen.vwView2.refresh();

            screen.vwView2.refresh();

        });

    I need that function because computed properties do not work in the HTML client. Or I never could get them to at least. So all of my calculated properties are being handled in my SQL views. So I need to refresh after saving.

    After the commitChanges(), can I look for the validation error before doing the refresh's and instead of refreshing display the validation error?

    Thanks (and sorry for the blue text? Pasting is odd in this forum)

    Jeremy

    Friday, December 16, 2016 9:46 PM

Answers

  • Got it, it was the custom save function. I needed to add a little to it so that the "Fail" would be thrown:

    return myapp.commitChanges().then(function fail(e) {

            screen.vwView1.refresh();

            screen.vwView2.refresh();

            screen.vwView2.refresh();

            throw e;

        });

    Hopefully this will help someone.

    • Proposed as answer by ADefwebserver Monday, December 19, 2016 4:19 PM
    • Marked as answer by Jeremy Crouch Wednesday, December 21, 2016 7:20 PM
    Friday, December 16, 2016 10:21 PM