Skip to main content

DataFormView.ValidateForm Event

Allows you to validate all data editors on the form.

Namespace: DevExpress.XamarinForms.DataForm

Assembly: DevExpress.XamarinForms.Editors.dll

NuGet Package: DevExpress.XamarinForms.Editors

Declaration

public event DataFormValidationEventHandler ValidateForm

Event Data

The ValidateForm event's data class is DataFormValidationEventArgs. The following properties provide information specific to this event:

Property Description
DataObject Gets or sets the data object that is associated with the data form.
Errors Provides access to a dictionary of error messages for data fields. Keys are data field names. Values are error messages. Error messages are displayed below data editors on the form.
HasErrors Gets or sets whether the data form is valid.
NewValues Provides access to a dictionary of new values that should be validated. Keys are data field names.

Remarks

You can handle the following events to validate user input:

  • ValidateProperty—allows you to validate a specific field on the form. Use the PropertyName event argument to determine the processed data field. The CurrentValue and NewValue arguments specify the current data field value and the value that should be validated. If the new value is not valid, set the HasError argument to true and use the ErrorText argument to notify the user about the error.
  • ValidateForm—allows you to validate all data fields on the form. This event stores new values and error messages in dictionaries, where keys are data field names.

See the following topic for more information: Validate User Input in Data Form View for Xamarin.Forms.

Example

The example below requires a phone number or email address.

using DevExpress.XamarinForms.DataForm;
// ... 

public partial class MainPage : ContentPage {
    public MainPage() {
        InitializeComponent();
        dataForm.DataObject = new PersonalInfo();
        dataForm.ValidateForm += dataForm_ValidateForm;
    }
    private void dataForm_ValidateForm(object sender, DataFormValidationEventArgs e) {
        if(e.NewValues["Email"] == null && e.NewValues["PhoneNumber"] == null) {
            e.HasErrors = true;
            e.Errors["Email"] = e.Errors["PhoneNumber"] = "Email address or phone number is required.";
        }
    }
}
See Also