Property validation RRS feed

  • Question

  • Hello All,

    I have developed a Lightswitch cloud app in VS 2013 and I am trying to validate the screen data with custom validation.

    The app has 2 screens, 1 to add Client info (parent), and 1 to add child Location(s) info.

    Intrinsic validation works on fields on the Client screen. It does not work on the Location screen. (meaning when a field loses focus validation occurs and error is displayed).  The property_Validate events are not firing for fields on the Client screen or Location screens. (I put a trap to debug)

    This is a sample or my code for Last Name. Intrinsic validation is Required. 

    Namespace LightSwitchApplication

        Public Class Client

            Private Sub Client_Last_Name_Validate(results As EntityValidationResultsBuilder)
                If Me.Client_Last_Name IsNot Nothing AndAlso
                 Not System.Text.RegularExpressions.Regex.IsMatch(Client_Last_Name, "^[a-zA-Z]+$") Then
                    results.AddPropertyError("Invalid characters in FirstName. Only alphabets allowed.")
                End If
            End Sub
        End Class

    End Namespace

    I reviewed this blog and it is pretty simple except mine does not work. This is a change set scenario.


    Thursday, February 18, 2016 4:09 AM


  • Hi willContest,

    According to your description, you want to validate the input value on client side and after the text box lose focus it will display the error message immediately.

    Please add the validate code in the text box's postRender function on screen. For example, I have a Age field which need to validate the input value can't be smaller than 0. Then I will add below code in the postRender.

    myapp.AddEditCustomer.Age_postRender = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind("value", function (value) {
            contentItem.validationResults = [];
            if (value < 0) {
                contentItem.validationResults = [
                    new msls.ValidationResult(contentItem.details, "Error Message")

    Best Regards,

    • Proposed as answer by Angie Xu Monday, February 29, 2016 6:57 AM
    • Marked as answer by Angie Xu Monday, February 29, 2016 6:57 AM
    Friday, February 19, 2016 9:24 AM