Inconsistent validation and binding behavior

Hi team,

I have just started using your Xamarin SfDataForm, and must say I'm impressed with the functionality out of the box.

My application is Xamarin Forms using Prism / Unity, and I have been able to configure the DataForm mostly to my liking, but have a couple of issues that I've been unable to solve that I'm hoping you can help with.

1. Validation
I have a view containing a DataForm, with its DataObject set to the underlying view model and several DataFormTextItem elements defined for properties exposed by the view model.  Validation is set up using Data Annotations, and I have observed an issue where validation occurs immediately for properties directly on the view model, but validation of properties of child objects does not occur immediately when the text is changed.

2. Bound data not updated
In the same view, if any of the underlying data changes the corresponding field in the DataForm is not updated.  The properties all implement INotifyPropertyChanged which can be proven by the observing the same properties bound to normal Entry controls in the same view.

I have attached a sample solution that illustrates these issues.

Steps to observe difference in validation behavior:
  1. Launch UWP application
  2. Delete the text in the View Model Username field
  3. Note that the validation error message is shown when the last character is deleted
  4. Delete the text in the Child Object Username field using the Backspace key
  5. Note that the validation error message is NOT shown when the last character is deleted
  6. Set focus to a different field - validation error message still NOT shown
  7. Set focus to Child Object Username field - validation error message still NOT shown
  8. Set focus to a different field - this time validation error message IS shown
  9. This only appears to affect nested properties of objects in the view model.
Steps to observe bound data not updating:
  1. Launch UWP application
  2. Note that the values of View Model Username, Child Object Username, View Model Username (Direct Binding) and Child Object Username (Direct Binding) all show the text "Delete Me"
  3. Click the Toggle Usernames button
  4. Note that View Model Username (Direct Binding) and Child Object Username (Direct Binding) are cleared, but the data form fields View Model Username and Child Object Username are not
  5. To prove that they are bound to the same objects, begin deleting characters from the data form field View Model Username
  6. Note that View Model Username (Direct Binding) is updated as each character is deleted
  7. To observe delayed update for the child object, begin deleting characters from the data form field Child Object Username
  8. Note that Child Object Username (Direct Binding) is NOT updated
  9. Set focus to a different field
  10. Note that Child Object Username (Direct Binding) IS now updated
  11. You can also observe that the binding and validation are updated at different times by deleting all the text from Child Object Username and setting focus to a different field, which updates Child Object Username (Direct Binding) but does NOT show the validation error message
  12. Set focus on and off Child Object Username and the validation error message is eventually updated
To work around the validation issue I have implemented display properties in the view model which are mapped from and to the child object during load and save respectively.  This could be argued to be better design by taking validation out of the model, but I do feel that the underlying issue needs looking at.

For the binding issue I have not come up with a work around, as I only spotted this while testing the validation issue, and it does not affect my application as yet.

Kind regards,
James

Attachment: DataFormIssues_167750f9.zipx

9 Replies

MS Muniappan Subramanian Syncfusion Team April 16, 2020 01:47 PM UTC

Hi James,

Thank you for contacting Syncfusion support.

Currently we are analyzing your query “Inconsistent validation and binding behavior” and we will update you further details on or before April 21, 2020. We appreciate your patience until then.

Regards,
Muniappan S


SS SaiGanesh Sakthivel Syncfusion Team April 21, 2020 01:59 PM UTC

Hi James, 
 
#1.Regarding Validation issue and Child object username not update until change focus issue 
We have fixed the issue and included the issue fix in our latest Weekly NuGet release update version 18.1.0.45 which is available for download (nuget.org).
  
 
We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you would require any further assistance. 
 
#2.Regarding two way binding issue 
Currently we are working on the reported issue and we will update you further details on or before April 23, 2020. We appreciate your patience until then.  
  
Regards, 
SaiGanesh Sakthivel


JC James Cecil April 21, 2020 08:16 PM UTC

That's great, many thanks for looking at these so quickly.

Kind regards,
James


MS Muniappan Subramanian Syncfusion Team April 22, 2020 08:50 AM UTC

Hi James Cecil, 
 
Thank you for the update. 
 
As promised, we will share further details for Query 2 on April 23, 2020. We appreciate your patience until then. 
 
Regards, 
Muniappan S. 



SS SaiGanesh Sakthivel Syncfusion Team April 23, 2020 02:46 PM UTC

Hi James,

Thank you for the patience.

we have checked the reported query “Clear and update the data in the editor while pressing toggle button ” from our end. We would like to inform you that you can achieved the requirement by using the UpdateEditor  in the Toggle Command. Please refer to the following code snippet for your reference.

 
Code snippet 
private void Toggle(object dataForm) 
{ 
    if (string.IsNullOrWhiteSpace(User.Username)) 
    { 
        User.Username = "Delete Me"; 
    } 
    else 
    { 
        User.Username = null; 
    } 
 
    if (string.IsNullOrWhiteSpace(VmUsername)) 
    { 
        VmUsername = "Delete Me"; 
    } 
    else 
    { 
        VmUsername = null; 
    } 
    (dataForm as SfDataForm)?.UpdateEditor("User.Username"); 
    (dataForm as SfDataForm)?.UpdateEditor("VmUsername"); 
} 
 
 
We have attached the tested sample in the following link 
 
We hope this helps. Please let us know if you need any further assistance. 

Regards,
SaiGanesh Sakthivel
 



JC James Cecil April 24, 2020 08:13 PM UTC

Hi SaiGanesh,

Thanks for the workaround.

Will the underlying issue with the binding be fixed at some point?  I ask because the workaround will add overhead if many fields need to be manually refreshed, for example if updating a number of objects/properties.  The workaround also adds complexity when using the MVVM pattern as it requires a behavior to be added to bind the UpdateEditor method of the data form to a command in the view model.

Kind regards,
James


SS SaiGanesh Sakthivel Syncfusion Team April 27, 2020 12:49 PM UTC

Hi James, 
 
Thank you for the update. 
 
We would like to inform you that the two way data binding is worked on the dataform when the NotifyPropertyChanges property is set into true in SfDataform. As per implementation of Dataform, the notifypropertychanges is worked for only direct view model object and not applicable for Child model object for that case you can use the updateEditor for changing the value in the editor. 
 
Please refer to the following UG Documentation for the Two way data binding 
 
We hope this helps. Please let us know if you need any further assistance. 
 
Regards, 
SaiGanesh Sakthivel


JC James Cecil May 1, 2020 10:31 AM UTC

Hi SaiGanesh,

Thanks for looking into this for me.  I do think this binding behavior differs from other controls, but at least there is a functional workaround.

To avoid the need to use Update Editor I will continue to map my business objects to properties of the view model for display/editing.

Kind regards,

James



MS Muniappan Subramanian Syncfusion Team May 4, 2020 07:36 AM UTC

Hi James Cecil, 
 
Thank you for the update. 
 
We are glad that our solution meets your requirement. Please let us know if you need any further update. As always, we are happy to help you out. 
 
Regards, 
Muniappan S. 


Loader.
Up arrow icon