How to set the label for Validation errors?

5 posts, 0 answers
  1. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 19 Apr 2012 Link to this post

    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?

  2. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 23 Apr 2012 Link to this post

    Any ideas?  I'm lost.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 24 Apr 2012 Link to this post

    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 >>
  5. Nivin
    Nivin avatar
    1 posts
    Member since:
    Nov 2012

    Posted 01 Nov 2012 Link to this post

    Hello Ivan,

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

    Thank you.
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 06 Nov 2012 Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready