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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set HasError in TextInputLayout from Entry?

Thread ID:





145011 Jun 1,2019 02:30 PM UTC Jun 4,2019 11:56 AM UTC Xamarin.Forms 1
Tags: SfTextInputLayout
Andrea Ferrari
Asked On June 1, 2019 02:30 PM UTC

I've an entry for email with a behavior checking if the field is correct.
In XAML is:

<inputLayout:SfTextInputLayout ContainerType="Outlined" Hint="Indirizzo Email" ErrorText="L'indirizzo email non è valido">
    <Entry TextColor="White" Text="{Binding Email}" Keyboard="Email" IsVisible="{Binding IsNotPartner}" >
            <local:EmailValitationBehavior />

The Behavior is:

public class EmailValitationBehavior : Behavior<Entry>
        const string emailRegex = @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +

        protected override void OnAttachedTo(Entry bindable)
            bindable.Unfocused += HandleCompleted;
        void HandleCompleted(object sender, EventArgs e)
            Entry s = (Entry)sender;
            bool IsValid = (Regex.IsMatch(s.Text, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
            s.TextColor = IsValid ? Color.Blue : Color.Red;
            (s.Parent as SfTextInputLayout).HasError = IsValid ? false : true;
        protected override void OnDetachingFrom(Entry bindable)
            bindable.Unfocused -= HandleCompleted;

I've tryied to set the HasError of the Parent of Entry, but its doesn't work.
How to do that in a MVVM environment (PRISM)?

Thanks a lot and have a nice day,

Bharathiraja K [Syncfusion]
Replied On June 4, 2019 11:56 AM UTC

Hi Andrea, 
Thank you for your interest in Syncfusion products. 
We have prepared the sample based on your requirement. Please refer the below code snippet for your understanding. 
Code Snippet [C#]: 
private void Entry_Unfocused(object sender, FocusEventArgs e) 
Entry inputView = (Entry)sender; 
bool IsValid = (Regex.IsMatch(inputView.Text, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250))); 
inputView.TextColor = IsValid ? Color.Blue : Color.Red; 
model.TextHasError = !IsValid; 
You can also achieve your requirement by using custom behavior with below change in your code snippet. 
Code Snippet [C#] 
(s.Parent.Parent.Parent as SfTextInputLayout).HasError = IsValid ? false : true; 
Please download the sample from the below link. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon