DataForm ValidationMode and CommitMode behaviour isn't working correctly and seems to affect how the datepickers work

1 Answer 48 Views
DataForm DatePicker
Top achievements
Rank 1
Angus asked on 23 May 2023, 10:06 AM

Hi I have attached my sample application where I've been trying out the RadDataForm and the behaviour seems inconsistent. 

I have a few scenarios where the validation and commit modes are behaving differently to how the docs suggest they should. I have laid them out in the XAML for MainPage to make it easy for you to test. 

Scenario 1 - Form level settings:

When I apply ValidationMode="LostFocus" to the whole form it still validates on property changed, UNLESS I also set CommitMode to LostFocus. You can test this by uncommenting each option in my MainPage.xaml file. The Name field will validate as soon as you start typing.

Scenario 2 - Control level settings:

ValidationMode="LostFocus" on the control level only doesn't seem to work at all, even with commit = lost focus.

In order to get my form to behave how I want, I have to set the form level validation AND commit to "LostFocus", however this now introduces another issue. The datepickers don't set their values on LostFocus (because I don't think they get focus since they use a popup), and with the form overriding it, it also doesn't commit the value on property changed, even if I set it on the individual datepicker control. Which means if I have any custom validation around these properties, it won't work properly because the values have not been set.

In my case I wrote a custom validator to check that StartDate is always before EndDate. If the form is set up with no options, this works correctly, but if I add LostFocus so that my RadEntries behave correctly, when my validator fires for the dates, the value of EndDate is always not set. I have to manually commit it with form.CommitChanges.

This doesn't seem like correct behaviour, unless I'm misunderstanding the docs.

Any help would be appreciated :)

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 25 May 2023, 02:32 PM


How ValidationMode and CommitMode work?

Simply put, ValidationMode and CommitMode relate to the ValidateChanges and CommitChanges methods of the DataForm. The properties specify whether and when the DataForm should call the corresponding methods. In this regard, ValidateChanges validates the values of the DataForm without committing them to the underlying model, displaying any potential validation errors to the user, when necessary. In contrast, CommitChanges validates the values of the DataForm and commits them to the underlying data model, as long as all validation rules have passed successfully. Currently, there is no scenario when the DataForm can commit changes to the model, without validating them first.

I believe, the biggest confusion comes when ValidationMode is set to LostFocus, while CommitMode is set to PropertyChanged. In that case, since CommitChanges is called on every property change, triggering ValidateChanges on every property change as well. In that particular case, setting ValidationMode to LostFocus has no effect. To make things work as expected, when ValidationMode is set to LostFocus, you have to set CommitMode to LostFocus or Explicit as well. The docs is updated, it will be live soon.

We tend to avoid committing invalidated changes to the model, otherwise that would mean:

 - The developers would have to duplicate all the validation logic themselves, otherwise there is a risk to store the data in an invalid or inconsistent state.

 - The developers must account for the fact that sometimes certain changes cannot be applied and there is no visual indication to the end user.
Consider the following simple scenario:


public class Employee
    public double Salary { get; set; }


If CommitMode is set to PropertyChanged, ValidationMode is set to LostFocus, but we do not validate during commit, what would happen if the user enters the text "ABC" in the text field? Since we cannot convert that text to double, but we do not show any validation errors during commit also, that change would simply be lost, without any visual warning to the end user, unless he/she tabs out of the field.

Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

DataForm DatePicker
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question