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

Styling the message displayed by a custom validator for a masked numeric input control

3 Answers 201 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 26 Jul 2013, 09:24 PM
I've put a RadMaskedNumericInput control onto window. To that I wanted to add validation. Here's the custom class I came up with:

public class ByteValidation : ValidationRule
{
    private byte min = 0;
    private byte max = byte.MaxValue;
 
    //The Minimum and Maximum values are there to restrict how low and how high the
    //stored value can be.
    public byte Minimum
    {
        get { return min; }
        set { min = value; }
    }
 
    public byte Maximum
    {
        get { return max; }
        set { max = value; }
    }
 
    public string ErrorMessage
    { get; set; }
 
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        if (value == null)
        {
            return new ValidationResult(true, null);
        }
 
        byte tmp;
 
        try
        {
            double dTmp = (double)value;
            tmp = (byte)dTmp;
        }
        catch (Exception)
        {
            return new ValidationResult(false, "Invalid value");
        }
 
        if (tmp < min || tmp > max)
        {
            return new ValidationResult(false, ErrorMessage);
        }
 
        return new ValidationResult(true, null);
    }
}

and here's the XAML:

<telerik:RadMaskedNumericInput Mask="##" Margin="550,0,0,0" Grid.Row="1" FontSize="16" VerticalAlignment="Bottom" FontFamily="Century Gothic">
    <telerik:RadMaskedNumericInput.Value>
        <Binding Path="DaysPaidLast30">
            <Binding.ValidationRules>
                <local:ByteValidation Minimum="0" Maximum="30" ErrorMessage="Value must be between 0 and 30." />
            </Binding.ValidationRules>
        </Binding>
    </telerik:RadMaskedNumericInput.Value>
</telerik:RadMaskedNumericInput>

This all works fine.

In testing I discovered that if I put in some invalid numeric data, then I'll get a gold border and a popup message. Is that color standard with the RadMaskedNumericInput? Can that be styled?

xxx

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 31 Jul 2013, 08:14 AM
Hi Rod,

Let me make a quick clarification. When you input an invalid number, the control visualizes a red border. You actually see it orange when you hover or focus the RadMaskedNumericInput, because the control visualizes an yellow border when it is in Focused state. Please note that when the focus is somewhere else the border remains red.

In order to customize that border you can change the Focused state of the control. To do that, you can extract and edit the default template of the control (read more).

Please give this approach a try and let me know if it works for you.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Rob Ainscough
Top achievements
Rank 1
answered on 17 Feb 2017, 02:58 AM

I'm having a similar issue, except the error text (red border to the left of the control) has a red border but the internal text is white on an almost white background making it almost impossible to read the error text in the red box (the background of the error box should be red per default for Microsoft controls like TextBox).

I'm using a Silverlight project.  I don't see any ability to change this behavior.

NOTE: all my other trapped Errors that are NOT Telerik controls (i.e. TextBox) show the red error box correctly ... red box outline with red background and white text, only the telerik controls shows a light almost white background???

Any suggestions?   I'm using the latest 2017 build for Silverlight Telerik controls.

Cheers, Rob.

 

0
Evgenia
Telerik team
answered on 21 Feb 2017, 05:28 PM
Hi Rob,

This is to inform you that you have already received an answer to your inquiry on the other forum thread started by you. I suggest that we continue any further conversation on this topic there so that we avoid duplicate content in our forums.

Regards,
Evgenia
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Rod
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Rob Ainscough
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or