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

Multiple RadDataForms in RadTab - User navigating away when in edit mode

2 Answers 104 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Titus
Top achievements
Rank 1
Titus asked on 23 Jan 2012, 04:35 AM

RadControls for Silverlight, v.2011.3.1220.1040 (Dev)

My application uses the following tables: Customers and Logins (One Customer can have many user accounts (logins)).

I am using RadDataForm to edit the Logins collection of the customer. The user is allowed to add/delete/update logins to the customer account and finally click Save to save (datacontext.SubmitChanges) the changes.

When the user edits/adds a login record and clicks the 'Save' button the application throws an InvalidOperationException stating that the login record is being edited and need to call Commit or CancelEdit before submitting.

I added code to check if there is any login that is being edited and handle it.
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
    bool canSave = true;
 
    canSave = HandlePendingEdit();
 
    if (canSave)
    {
        _context.SubmitChanges();
    }
}
 
private bool HandlePendingEdit()
{
    bool canSave = true;
 
    Login login = null;
    IEditableCollectionView logins = (IEditableCollectionView)this.LoginsDataForm.ItemsSource;
    if (logins.IsAddingNew)
    {
        login = logins.CurrentAddItem as Login;
    }
    else if (logins.IsEditingItem)
    {
        login = logins.CurrentEditItem as Login;
    }
 
    if (login != null)
    {
        List<System.ComponentModel.DataAnnotations.ValidationResult> validationResults = new List<System.ComponentModel.DataAnnotations.ValidationResult>();
 
        // check if the currently being edited item has errors
        if (!Validator.TryValidateObject(login, new ValidationContext(login, null, null), validationResults))   // show the errors and cancel save
        {
            canSave = false;
 
            foreach (var item in validationResults)
            {
                login.ValidationErrors.Add(item);
            }
        }
        else // No errors - commit the edit and procedd with the save
        {
            this.LoginsDataForm.CommitEdit();
        }
    }
 
    return canSave;
}


This works ok except for the following:

The LoginId field is a required field.

When the user clicks ok in the RadDataForm without entering a value in the Login field, the form shows the validation error in the control and also in the validation summary.

But when the user clicks 'Save' without hitting OK first, then my code that triggers the validation causes the error to be shown in the Login input control (TextBox) but not in the ValidationSummary.

I have a sample (project and the script to create the two sample tables) to reproduce this behavior. I am not able to attach the project files though.

Steps to reproduce:
1. Click Edit icon in the RadDataForm
2. clear the Login data field
3. Click Ok to end the edit
4. You should see the validation error (both in textbox and validation summary) - attached screenshot - Validation Summary and textbox error.png

5. Cancel Edit
6. Click Edit again
7. Clear Login data field
8. Click 'Save' button at the top without clicking Ok/Cancel of RadDataForm
9. The error message is shown only in the text box not in the Validation Summary - attached screenshot - Textbox only error.png

What am I doing wrong / missing? I want to show the validation error in the validation summary in both scenarios.

Is there a better way to handle the scenario of the user clicking the Save button while in edit mode?

Thanks for your time

Please let me know if it will be helpful if I sent my sample project...

2 Answers, 1 is accepted

Sort by
0
Titus
Top achievements
Rank 1
answered on 23 Jan 2012, 04:38 AM
Though I encountered this issue with multiple dataforms in tab controls, I was able to reproduce this behavior even with one dataform.
0
Maya
Telerik team
answered on 23 Jan 2012, 09:52 AM
Hello Titus,

I have tried to reproduce the issue you reported, but I was not able to get the same behavior. Could you take a  look at the sample attached to verify whether I am missing something ?  

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DataForm
Asked by
Titus
Top achievements
Rank 1
Answers by
Titus
Top achievements
Rank 1
Maya
Telerik team
Share this question
or