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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Retrieve errors from the form and bind to a button

Thread ID:

Created:

Updated:

Platform:

Replies:

146599 Aug 9,2019 04:24 PM UTC Sep 3,2019 07:10 AM UTC Xamarin.Forms 6
loading
Tags: SfDataForm
Davide
Asked On August 9, 2019 04:24 PM UTC

Hello,
I'm using SfDataForm with MVVM pattern and  with a custom class bound as source.
I'm using also it with validationmode.lostfocus.

I'd like to bind the IsEnabled property of a button to the errors count of the sfdataform (no errors means the button is enabled), but I do not understand how to get errors dinamically from the object in my viewmodel.

How can I achieve this?
Thanks,
Davide

Subburaj Pandian Veluchamy [Syncfusion]
Replied On August 12, 2019 07:49 AM UTC

Hi Davide, 
  
Thank you for contacting Syncfusion support. 
  
We have analyzed your requirement of “Get validation error count in DataForm”.Validation error count can get from ValidationCompletedEvent if you are using DataFormExplicitValidation. Since you are using LostFocus ValidationMode, your requirement can be achieved using DataForm Validated event. ValidatedEvent will be triggered after each DataFormItem validated, in which you can check for whether all fields are valid usingIsValid property of DataFormItem class. 
  
Code Snippet: 
        
private void DataForm_Validated(object sender, ValidatedEventArgs e) 
{ 
          button.IsEnabled = (sender as SfDataForm).ItemManager.DataFormItems.TrueForAll(x => (x asDataFormItem).IsValid); 
  } 
  
We have prepared a simple sample for the same, 
 
Sample link: DataForm 
  
We hope this helps. Kindly revert us if you have any concern. 
 
Regards,
Subburaj Pandian V   


Davide D Angelo
Replied On August 16, 2019 01:24 PM UTC

Thank you Subburaj,
your answer has solved the issue, but after implemented it, I decided to change the validation mode to "Explicit".
I'd like to validate the form (sfdataform) in my viewmodel, when a button with command has been clicked: how can I achieve this? I'd like to avoid to call validate method of sfdataform in my page.xaml.cs page.


Also, as second question, is there any option to validate the entries in the form in the lost focus and also call the validation mode Explicit?
Regards,
Davide

Ganeshamoorthy Chandramoorthy [Syncfusion]
Replied On August 19, 2019 02:12 PM UTC

Hi Davide, 

 

Thanks for the update.

 

Currently we are analyzing on your query, we will analyze and update you the further details in two business days (August 21, 2019). We appreciate your patience until then.  

 

Regards,
Ganeshamoorthy C 


Subburaj Pandian Veluchamy [Syncfusion]
Replied On August 21, 2019 11:01 AM UTC

Hi Davide, 
  
Thank you for your patience. 
  
Query 1: Regarding validation using Button command in ViewModel 
DataForm can be validated in ViewModel using Button Command. While button has clicked pass DataForm instance as Command parameter and validate the DataForm in ViewModel using DataForm Validate method. 
  
[Code Snippet] 
[XAML] 
<dataForm:SfDataForm x:Name="dataForm" DataObject="{Binding LoginInfo}" Grid.Row="0"ValidationMode="LostFocus" CommitMode="LostFocus"/> 
  
<Button x:Name="validateButton" Grid.Row="1"  Text="Submit" 
    Command="{Binding Path=BindingContext.ValidateCommand, Source={x:Reference Name=dataForm}}" CommandParameter="{Binding Source={x:Reference Name=dataForm}}"/> 
  
[C#]        
public DataFormViewModel() 
{ 
     loginInfo = new DataFormModel(); 
     this.ValidateCommand = new Command<object>(this.OnValidate); 
} 
  
public Command<object> ValidateCommand { getset; } 
  
private void OnValidate(object dataForm) 
{ 
       var dataFormLayout = dataForm as Syncfusion.XForms.DataForm.SfDataForm; 
       dataFormLayout.Validate(); 
  } 
  
Query 2: Regarding validating DataFormItems in both LostFocus and Explicit validation 
DataFormItems can be validated explicitly even if ValidationMode set to LostFocus or PropertyChanged but If ValidationMode set to Explicit, then explicit validation only can be done. So, set ValidationMode to LostFocus and call explicit validation using Validate() method both will work fine with DataForm. 
  
We have prepared a simple sample including solutions for both queries,         
 
Sample link: DataForm 
  
We hope this helps. Kindly revert us if you have any concern. 
  
Regards,
Subburaj Pandian V  


Davide D Angelo
Replied On September 2, 2019 09:47 AM UTC

Hi Subburaj,
that was what I needed.
It works
Thank you,
Davide 

Subburaj Pandian Veluchamy [Syncfusion]
Replied On September 3, 2019 07:10 AM UTC

Hi Davide,  
   
Thank you for the update. We are glad that the given solution meets your requirement.

Please get in touch with us, if you would require any further assistance.

 
Regards,
Subburaj Pandian V  


CONFIRMATION

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