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

Validation with DataTemplates

6 Answers 152 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.
Jeff Buechler
Top achievements
Rank 1
Jeff Buechler asked on 08 Sep 2011, 07:28 PM
It seems that validation only works when using AutoGenerateFields. When using DataTemplates the field with an error is flagged but the form fires the EditEnded event and returns to the read only state in spite of the error. Is there any way around this? Will it be fixed in a coming release?

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 09 Sep 2011, 07:47 AM
Hello Jeff Buechler,

Would you please shed some more light on the validation logic you have applied? Do you use Data Annotations attributes, or some of the validation interfaces (i.e. IDataErrorInfo).

Kind regards,
Ivan Ivanov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
vk
Top achievements
Rank 1
answered on 09 Sep 2011, 08:11 AM
Try setting ValidatesOnExceptions and NotifyOnValidationError to true for each binding.
<telerik:DataFormDateField Label="Load date"
DataMemberBinding="{Binding LoadDate, Mode=TwoWay,
ValidatesOnExceptions=True, NotifyOnValidationError=True}" />

0
Jeff Buechler
Top achievements
Rank 1
answered on 09 Sep 2011, 12:55 PM
In my actual project I'm using Data Annotations. I've also tried using IDataErrorInfo by modifying a sample provided in response to another post. The only difference was that with Data Annotations I did get the error message to appear. With IDataErrorInfo, there was no indication at all of validation. Below is the code from the modified sample. Am I missing something?

<UserControl.Resources>
        <DataTemplate x:Key="editTemplate">
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Prop1" />
                    <TextBox Text="{Binding Prop1, Mode=TwoWay,ValidatesOnExceptions=True, NotifyOnValidationError=True}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Prop2" />
                    <TextBox Text="{Binding Prop2, Mode=TwoWay,ValidatesOnExceptions=True, NotifyOnValidationError=True}" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="readOnlyTemplate">
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Prop1" />
                    <TextBox Text="{Binding Prop1, Mode=TwoWay}" IsReadOnly="True" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Prop2" />
                    <TextBox Text="{Binding Prop2, Mode=TwoWay}" IsReadOnly="True" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
 
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadDataForm x:Name="radDataForm"
                             AutoGenerateFields="False"
                             EditTemplate="{StaticResource editTemplate}"
                             ReadOnlyTemplate="{StaticResource readOnlyTemplate}"
                             NewItemTemplate="{StaticResource editTemplate}"
                             >
             
        </telerik:RadDataForm>
    </Grid>
</UserControl>
 
 
namespace SilverlightApplication202
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            radDataForm.ItemsSource = new ObservableCollection<TestItem>() { new TestItem() { Prop1 = "77", Prop2 = "43" } };
            radDataForm.AutoGeneratingField += new EventHandler<Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs>(radDataForm_AutoGeneratingField);
        }
 
        void radDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
        {
            if (e.PropertyName == "Error")
            {
                e.Cancel = true;
            }
            e.DataField.DataMemberBinding.ValidatesOnDataErrors = true;
            e.DataField.DataMemberBinding.NotifyOnValidationError = true;
        }
    }
 
    public class TestItem : IDataErrorInfo
    {
        public string Prop1 { get; set; }
        public string Prop2 { get; set; }
 
        public string Error
        {
            get { return null; }
        }
 
        public string this[string columnName]
        {
            get
            {
                string error = "";
                if (this.Prop1 == "" || this.Prop1 == null )
                {
                    error = "Prop1 is required";
                }
                if (this.Prop2 == "" || this.Prop2 == null)
                {
                    error = "Prop1 is required";
                }
                return error;
            }
        }
    }
 
}

0
Ivan Ivanov
Telerik team
answered on 14 Sep 2011, 04:32 PM
Hello Jeff Buechler,

Please, excuse us for the inconvenience. This is a known issue with RadDataForm. We will provide a solution for it in one of our internal builds in the close future.

Best wishes,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Nick Wood
Top achievements
Rank 1
answered on 03 Aug 2012, 01:33 AM
Has this error been fixed becuase I am playing around with the CRM demo source and cannot get the DateTimePicker to raise any DataValidations, but the same time picker does raise data validations notifications outside of the DataForm.

Nick
0
Ivan Ivanov
Telerik team
answered on 03 Aug 2012, 12:57 PM
Hi Nick,

Would you please, confirm what type of Validation you are using? The previous posts in this thread refer to the IDataErrorInfo-based validation, but such is not implemented on our CRM demo. Moreover, you should set the Binding's Validation properties (ValidatesOnDataErrors/Exceptions) by yourself, when controls different from the DataField controls are used in some of RadDataForm's templates. Would it be possible for you to isolate the issue in a sample project and send it to us, so that we can debug it on our side?

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataForm
Asked by
Jeff Buechler
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
vk
Top achievements
Rank 1
Jeff Buechler
Top achievements
Rank 1
Nick Wood
Top achievements
Rank 1
Share this question
or