IT Link Solutions Blog | How to validate a textbox on focus out in MS LightSwitch Application?

How to validate a textbox on focus out in MS LightSwitch Application?

by Administrator 15. April 2016 00:24

 

I am currently working on a LightSwitch HTML client application in which I faced an issue of validating textbox. For example, upon setting up a Boolean Yes/No field to Yes, the relevant text field must contain a value. I figured out that it can be done by using focus out event of that textbox, so I need to find out a way to implement focus out event of a textbox in LightSwitch.
 

You cannot validate a textbox on focus out by using LightSwitch jquery API wrapper. You will have to achieve it by using jQuery focusout event.

 

$(element).find("input").focusout(function () {

        try {

 

            if ($(this).val() && !ValidateEmail($(this).val())) {

                contentItem.screen.findContentItem("EmailAddress").validationResults = [

new msls.ValidationResult(                       

contentItem.screen.PatientApplicant.details.properties.EmailAddress,

"Please enter a valid Email '!'.")

                ];

                $(this).focus();

                returnfalse;

               

            } else

                contentItem.screen.findContentItem("EmailAddress").validationResults = null;

        } catch (e) {}

    });

 

function ValidateEmail(email) {

    var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

    return expr.test(email);

};

 

It will probably resolve the issue, if not you can always seek help from our MS LightSwitch application experts anytime you want.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Review Us!

Connect with Us

Tag cloud