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

How to set the label for Validation errors?

4 Answers 291 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 19 Apr 2012, 11:21 PM
I have a RadDataForm with a number of DataFormDataField. They are bound to an object of a class that implements IDataErrorInfo, and when a field control validation, it's surrounded by a red box and an error message is displayed at the bottom of the form, prefixed by the DataFormDataField's label.

I have three problems:

  1. What if the label I want to display in the form isn't the label I want to display with the error message?  I have a couple of controls where I want the label to include a closing colon, and that results in two colons in the error message.
  2. What if the control is not a DataFormDataField? The error message for these seems to display the name of the property it is bound to - and that's usually not what I want.
  3. I have added BindingGroups to a number of GroupBoxes on the form, that return errors if something about the group is wrong. (None of the fields in the group have been selected, etc.) These display an error message that just has a colon, with no label name at all.

Seems like these are all different aspects of the same problem. Where does the form's error message display look, to get the names it includes, and how can I override this so as to use the labels I choose?

4 Answers, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 23 Apr 2012, 08:08 PM
Any ideas?  I'm lost.
0
Ivan Ivanov
Telerik team
answered on 24 Apr 2012, 05:25 PM
Hi Jeff,

Please excuse mo for the delayed answer. RadDataForm internally manages binding DataErrors and there is no easy way to make big changes in this mechanism. However, you can try disabling it. Basically it executes this logic on the BindingValidationError event, so that you can subscribe to it on DataFields' level and handle it there. Then you can implement your own custom validation errors like this:
radDataForm.ValidationSummary.Errors.Add(...);
Please, be advised that in case you choose this approach, you should also manage these errors removal from the validation summary. An alternative approach would be to retemplate the validation summary ItemTemplate, adding a converter that will generate the desired label names. As for the last point of your list, it will be great if you can send us a small project that illustrates your approach via a support ticket, so that we could debug it and implement a solution on our side. Please, do not hesitate to ask us for an example project if you have any difficulties while implementing the proposed approach, in case it meets your requirements.

Greetings,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Nivin
Top achievements
Rank 1
answered on 01 Nov 2012, 01:42 PM
Hello Ivan,

Could you please post some example code in which you have retemplated the validation summary ItemTemplate . 

Thank you.
0
Ivan Ivanov
Telerik team
answered on 06 Nov 2012, 04:58 PM
Hello Nivin,

You can create a new ControlTemplate for DataFormValidationSummary and set it through RadDataForm's ValidationSummaryStyle property. In this ControlTemplate you can set a new ItemTemplate to the ItemsControl placed in the summary. Please, use the latest internal build, if possible, as we have fixed a related issue there.

Kind regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Nivin
Top achievements
Rank 1
Share this question
or