This question is locked. New answers and comments are not allowed.
Re code below.
If I enter a character in the age field I get an error flagged ... OK
If I enter a name starting with B I get an error flagged ... OK
It also picks up the annotation "Display" and sets title to "User Name" ... OK
But I can't get the "Required" annotation to cause an error when name is blank ?
Note: I tried the standard RadForm and that also does not pick up on "Required"
Should it work, am I missing something ?
Thanks
Jim
If I enter a character in the age field I get an error flagged ... OK
If I enter a name starting with B I get an error flagged ... OK
It also picks up the annotation "Display" and sets title to "User Name" ... OK
But I can't get the "Required" annotation to cause an error when name is blank ?
Note: I tried the standard RadForm and that also does not pick up on "Required"
Should it work, am I missing something ?
Thanks
Jim
<
Grid
x:Name
=
"LayoutRoot"
>
<
telerik:RadDataForm
HorizontalAlignment
=
"Left"
Name
=
"DataForm1"
Height
=
"408"
Width
=
"449"
/>
</
Grid
>
Public Class Person
Private m_name As String
<
Display
(
name:
=
"User Name"
)>
<
Required
(
ErrorMessage:
=
"Name is required."
)>
Public Property name As String
Set(n As String)
If n.StartsWith("B") Then
Throw New ValidationException("Can't start with B")
Else
m_name = n
End If
End Set
Get
Return (m_name)
End Get
End Property
Public Property age As Integer
Public Sub New(n As String, a As Integer)
name = n
age = a
End Sub
End Class
8 Answers, 1 is accepted
0
Accepted
Hi Jim,
RadDataForm has no native support of the "Required" data annotation attribute yet. We plan this feature to be added in some of our future releases. For now, I would advise you to implement IDataErrorInfo on your business object class, in order to achieve your task. I have prepared an example project that illustrates this approach. An alternative solution is to explicitly validate your property regarding the attributes set like this:
Regards,
Ivan Ivanov
the Telerik team
RadDataForm has no native support of the "Required" data annotation attribute yet. We plan this feature to be added in some of our future releases. For now, I would advise you to implement IDataErrorInfo on your business object class, in order to achieve your task. I have prepared an example project that illustrates this approach. An alternative solution is to explicitly validate your property regarding the attributes set like this:
[Required(ErrorMessage=
"User Name is Required"
)]
public
string
UserName
{
get
{
return
userName; }
set
{
Validator.ValidateProperty(value,
new
ValidationContext(
this
,
null
,
null
) { MemberName=
"UserName"
});
userName = value;
}
}
Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Jim
Top achievements
Rank 1
answered on 02 Aug 2011, 03:51 PM
Thanks for the info
Will have a look tomorrow.
Regards
Jim
Will have a look tomorrow.
Regards
Jim
0
Brian
Top achievements
Rank 1
answered on 27 Jan 2012, 11:06 PM
Ivan,
Thanks for the sample. I would like one of my fields to be required, and I would like the form to indicate that it is required right away when a new object is created. I can force the required message to appear on the RadDataForm by validating my object when it is created, but the OK button on the RadDataForm is still enabled in this case. However, if I enter data in the field, tab away, then go back and clear the field and tab away, I not only get the required message, the OK button is disabled as well. Is there a way to get the OK button to be disabled either by default, or in response to my validation when the object is created?
Thanks,
Brian
Thanks for the sample. I would like one of my fields to be required, and I would like the form to indicate that it is required right away when a new object is created. I can force the required message to appear on the RadDataForm by validating my object when it is created, but the OK button on the RadDataForm is still enabled in this case. However, if I enter data in the field, tab away, then go back and clear the field and tab away, I not only get the required message, the OK button is disabled as well. Is there a way to get the OK button to be disabled either by default, or in response to my validation when the object is created?
Thanks,
Brian
0
Hi Brian,
We have introduced some improvements in RadDataForm validation with Q3 2011. Now there is item level validation that is carried out on commit, navigate etc. However, this validation errors do not disable the commit button - only property level validation errors do it. This behavior is similar to toolkit DataForm's validation behavior. I presume that you invoke Validator.ValidateProperty in your property setters, so the only way to cause a property level error is to access the respective setter.
All the best,
Ivan Ivanov
the Telerik team
We have introduced some improvements in RadDataForm validation with Q3 2011. Now there is item level validation that is carried out on commit, navigate etc. However, this validation errors do not disable the commit button - only property level validation errors do it. This behavior is similar to toolkit DataForm's validation behavior. I presume that you invoke Validator.ValidateProperty in your property setters, so the only way to cause a property level error is to access the respective setter.
All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Brian
Top achievements
Rank 1
answered on 31 Jan 2012, 05:16 PM
Ivan,
Actually, my class is a RIA services Entity, so the code-generated properties call Entity.ValidateProperty in the setters. When I set the value of my property to a non-valid value, the red outline and validation message appear on the field, but the OK button is not disabled. According to the documentation (http://msdn.microsoft.com/en-us/library/ff422361(v=vs.91).aspx), this method should throw ValidationException just like Validator.ValidateProperty, and the fields in the data form appear to recognize that the property value did not pass validation, but the OK button only seems to respond when the value I have set is actually entered into the field on the data form. This behavior occurs in both the Q2 2011 and Q3 2011 releases.
I have a working example of this if you would like to see it.
Thanks,
Brian
Actually, my class is a RIA services Entity, so the code-generated properties call Entity.ValidateProperty in the setters. When I set the value of my property to a non-valid value, the red outline and validation message appear on the field, but the OK button is not disabled. According to the documentation (http://msdn.microsoft.com/en-us/library/ff422361(v=vs.91).aspx), this method should throw ValidationException just like Validator.ValidateProperty, and the fields in the data form appear to recognize that the property value did not pass validation, but the OK button only seems to respond when the value I have set is actually entered into the field on the data form. This behavior occurs in both the Q2 2011 and Q3 2011 releases.
I have a working example of this if you would like to see it.
Thanks,
Brian
0
Hello,
Vlad
the Telerik team
Please send us the project via support ticket.
All the best,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Kirk
Top achievements
Rank 1
answered on 24 Feb 2012, 12:47 AM
I'm seeing a very similar problem to what Brian had. Was there a resolution for that?
0
Hello Kirk,
Would you please confirm which version of RadControls you are curently using? We have introduced some validation improvements for RIA Entities with Q1 2012 and I believe that this problem should be fixed with the mentioned version.
Ivan Ivanov
the Telerik team
Would you please confirm which version of RadControls you are curently using? We have introduced some validation improvements for RIA Entities with Q1 2012 and I believe that this problem should be fixed with the mentioned version.
Ivan Ivanov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>