This is a migrated thread and some comments may be shown as answers.

DataForm Validation

3 Answers 66 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 2
Harald asked on 04 Oct 2015, 08:34 AM

Hello,

how can I prevent the user can exit the form?

private void AddressDetails_ValidatingItem(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Address address = this.AddressDetails.CurrentItem as Address;
            try
            {
                if (address.LastName == null)
                {
                    throw new ValidationException("Das Feld Nachname darf nicht leer sein.");
                }
                //Save Changes
                SaveChanges();
            }
            catch (ValidationException ex)
            {
               RadWindow.Alert(ex.Message);
            }  
        }

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 07 Oct 2015, 12:30 PM
Hi Harald,

Can you please share some details on what exactly do you mean by exiting the form?

Additionally, I suggest you taking a look at our documentation on Validation, as the supported by RadDataForm validation approaches are demonstrated in it. You may also find the DataForm Validation - ValidatingItem() useful on the matter.

Regards,
Stefan X1
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Harald
Top achievements
Rank 2
answered on 11 Oct 2015, 02:09 PM
If a required field is empty, the Click on Commit-Button show a Alert and the User canĀ“t leave the Editmode of the DataForm.
0
Accepted
Petya
Telerik team
answered on 14 Oct 2015, 04:25 PM
Hi Harald,

One way to achieve that is through the CancelEventArgs exposed by the ValidatingItem event. Just set the Cancel property to true:
if (address.LastName == null)
    {
        throw new ValidationException("Das Feld Nachname darf nicht leer sein.");
        e.Cancel = true;
    }

Hope this helps.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataForm
Asked by
Harald
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Harald
Top achievements
Rank 2
Petya
Telerik team
Share this question
or