DataFormDataField validation

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

    Posted 11 Apr 2012 Link to this post

    I have a RadDataForm, with a DataFormDataField, that is bound to a Decimal property.

    I'm trying to get validation working, and I'm having some issues:

    1. When I have a validation error, and the DataFormDataField does not have its Label property set, the error is displayed using the name of the field, instead of the [Display(Name="xxx")] annotation.
    2. When I enter invalid characters (non-numeric), my Decimal property's setter is never called, instead the form displays a "Value 'xxx' could not be converted" error. I need to display a more meaningful message.
    3. I have a listener on the RadDataForm's ValidatingItem event - but that event is not called when I move focus from one field to another (which is when the above error messages appear.)
    4. I need to some level of validation on each keystroke. If the field can only hold 12 characters, an attempt to type a 13th should do nothing. If the user is typing in a field that can only hold numeric values, typing non-numeric characters should do nothing - the keyboard event should be swallowed, and the character should not appear in the field.  At a minimum, letters would be filtered, it'd be better if we could look at the new character and the existing content, and decide whether the new character can be applied without invalidating the field.  (If the field is bound to a decimal, it should allow numbers, and one decimal point. A second decimal point should be swallowed.)
  2. Maya
    Maya avatar
    4062 posts

    Posted 16 Apr 2012 Link to this post

    Hi Jeffrey,

    Firstly, I would recommend you to run through this article for a reference. Depending on the validation that you do, you can easily set ErrorMessage attribute.  
    Considering the validation of a numeric value when a string one is entered, this is handled by the Framework, not by RadDataForm - that is why the ValidatingItem event is not fired. Please run through this and this articles for a reference. 
    As for your last requirement, you can try implementing some custom logic in TextChanged event of the TextBox:

    public MainWindow()
                this.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(OnTextChanged), true);
            private void OnTextChanged(object sender, TextChangedEventArgs e)

    Another possible approach would be to implement the logic inside the setter of the property. 

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
  4. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 16 Apr 2012 Link to this post

    Some solutions I've found:

      2. ValidationRules can be configured to, and by default are, run prior to the conversion to the datatype of the bound variable.
      4. If you set UpdateSourceTrigger = PropertyChanged on a binding, the value will be validated every time it is changed. (The default is LostFocus).

    Still no luck on #1.
Back to Top