We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Async Method Calls in Form Validation

Hi.

I've been using SFTextBoxExt on my Windows Phone 8,1/RT app. I have also used validation with different types of criteria, and it looks pretty nice. Now I have a new criterion ("existing name in database") that requires me to do an asynchronous call to my database interface. What would be the best way to do this with SFTextBoxExt?

Best regareds,
-Juergen



5 Replies

VJ Victory Jessie Selvam D Syncfusion Team March 7, 2016 10:21 AM UTC

Hi Juergen,

Thank you for using Syncfusion products.

We suggest you to use the properties PopupDelay and MinimumPrefixCharacters to force SfTextBoxExt control for waiting a few seconds before filtering suggestions. During this waiting time, asynchronous call to Database can be performed for filtering the autocomplete source. We have prepared a sample for the same and you can download it from the following link:

Sample: TextBoxExt

Regards,
Jessie


Jürgen March 7, 2016 10:57 AM UTC

Hi Jessie.

Thank your for your help and going through the effort of providing an example. My apologies for not being more specific in my original question but I'm not sure how to apply your example in my case.

Data validation is done using the properties Error and this and their respective "getters". If, for instance, the user now enters something in the name field of my form, I want to ask the database if that name is already taken. In case of a duplicate I want to give the user immediate feedback, same as with other invalid input. This request is not likely to take a lot of time. But making async calls from a "getter", even if possible, is probably not going to work well.

So my approach now would be to handle this outside SfTextBoxExt validation using the LostFocus event. That basically creates a second validation structure and feels a bit redundant. Is there another way?

Thanks and regards,
-Juergen


VJ Victory Jessie Selvam D Syncfusion Team March 8, 2016 12:58 PM UTC

Hi Juergen,

Currently DataValidation can be performed in SfTextBoxExt control using the properties "Error" and their respective "this" getter. Making asynchronous Database calls in "Error" property getter will not yield expected result in validation, so we suggest you to perform validation in LostFocus event. We have prepared a sample for the same and you can download it form the following link:

Sample: TextBoxExt

Regards,
Jessie


Jürgen March 8, 2016 08:10 PM UTC

Hi.

Thanks once again for your efforts. Yes, something like this I had in mind. In the example you are actually testing for duplicates in both the LostFocus event and the this and Error getters.

It seems like setting the HasError property does not handle the formatting (red border) of the text box (triggered by returning non-empty string from this?).

Probably the best approach for my case is to fetch a list of existing names from the database upon page load and validate against that, which will likely also enable better performance for the validation.

-Juergen


VJ Victory Jessie Selvam D Syncfusion Team March 9, 2016 12:59 PM UTC

Hi Juergen,

Error template will be refreshed in SfTextBoxExt control only during the validation process. The "this" getter which performs validation will be invoked only when the property value is updated in binding source. If control loses focus without any change in text, then validation will not happen and setting HasError property at this point is of no use. So we suggest your approach of fetching the list of existing names from database on page load and validating against that as best approach in this scenario.

Regards,
Jessie

Loader.
Up arrow icon