New Posts New Posts RSS Feed: Field Level Validation
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Field Level Validation

 Post Reply Post Reply
Author
-ook View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Aug-2007
Location: Australia
Posts: 41
Post Options Post Options   Quote -ook Quote  Post ReplyReply Direct Link To This Post Topic: Field Level Validation
    Posted: 01-Aug-2013 at 5:39pm
Hello
 
I have implemented validation as per the TempHire reference application, and note that DataAnnotations may also be used on individual properties (I am using code first approach).
 
I am using DevExpress controls that apparantly do not support dataannotations but rather the IDataErrorInfo approach. I have added the IDataErrorInfo interface to my class and have placed the correct validation code in the 'string IDataErrorInfo.this[string columnName]' method. Yet still the control does not show an error. I suspect it is an MVVM thing or the fact I seem to be mixing two types of validation.
 
Anyone have any pointers?
 
Thanks
Mark
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 01-Aug-2013 at 5:53pm
This sounds like a DevExpress issue. Implementing IDataErrorInfo is redundant. DevForce entities implement IDataErrorInfo out of the box. If the controls don't show an error, then it is an issue with the control or possibly the binding. I recommend you contact DevExpress support. 


Back to Top
-ook View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Aug-2007
Location: Australia
Posts: 41
Post Options Post Options   Quote -ook Quote  Post ReplyReply Direct Link To This Post Posted: 01-Aug-2013 at 7:04pm
I have changed the control to a TextBox thus simplifying the issue by using standard out of the box controls. I would expect a red outline to be displayed. I should note that I am using WPF.
(this one seems to hint at more code required for WPF to get this to work)
My binding appears correct:
<TextBox Text="{Binding ReportedBy, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=true}"/>
In the model I have tried:
/// <summary>Gets or sets the person who reported the incident. </summary>
[DataMember]
[Required]
public string ReportedBy { get; set; }
and even added:
/// <summary>Gets or sets the person who reported the incident. </summary>
[DataMember]
[Required]
[IdeaBlade.Validation.RequiredValueVerifier(ErrorMessageResourceName = "ReportedBy")]
public string ReportedBy { get; set; }
If I attempt save the record it will display a validation error dialog listing the fields in question that are at fault, but still no difference to the TextBox
I have also added the custom style as recommended in the sample:
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"
/>
</Trigger>
</Style.Triggers>
</Style>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"
/>
</Trigger>
</Style.Triggers>
</Style>
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 01-Aug-2013 at 10:39pm
Yes, WPF validation is not straight forward. Works much better in Silverlight. It's often easier to use exception based validation in WPF. You found the right resources in our documentation. Follow those instructions and give exception based validation a try by changing VerifierOptions.ErrorNotificationMode as described here: http://drc.ideablade.com/devforce-2012/bin/view/Documentation/verification-ui#HVerificationwithaWPFUI
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down