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

Input general number

5 Answers 80 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
christina noel
Top achievements
Rank 1
christina noel asked on 24 Oct 2011, 07:39 PM
I want to validate that my user is inputting a number. I don't have a field to bind to, so I'm looking at masked numeric input.

The problem is, I usually don't have an exact mask that I require. In some case, any integer is valid. In some cases, any positive double is valid, regardless of the number of decimals, etc.

 Is maskednumericinput the best control for me? Or should I be using something else? I'd appreciate advice on how to get this working.

--Christina

5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 27 Oct 2011, 04:26 PM
Hello Christina Noel,

 Could you please examine this documentation article and let us know if it could be a good starting point for you?

Kind regards,
Petar Mladenov
the Telerik team

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

0
christina noel
Top achievements
Rank 1
answered on 27 Oct 2011, 06:26 PM
That's a great starting point, except for one problem: I don't have a class that I can add validation info to.

More information:
These controls are in a form that will be used to "Mass Update" several instances of a class to identical values. I can't modify the validation of the class itself (primarily because the class is defined in a .asmx and imported through a service reference -- this allows bindable properties, but the Web Site project doesn't have the silverlight validation objects and events, unless I'm missing something).

My first solution to this was to just allow generic input and then check to make sure that it was an integer, or a double, or whatever else was valid when the user hit Submit, and using a message box to let them know that they needed to fix values. I've gotten feedback that it would be better if the user knew before they hit submit that they've input something invalid or (better yet) that they could only input valid values in the first place.

I'm not worried about format or range, as long as it's a valid double or integer.

I've looked into manual validation (in on lose focus) but couldn't figure out how to do it without binding to a property with validation code, because I can't manually set the ValidationError (stupid internal class...). I was hoping to find some control that would help me.

--Christina
0
Accepted
Petar Mladenov
Telerik team
answered on 01 Nov 2011, 01:26 PM
Hi Christina Noel,

One thing you could do is to create a "wrapper" classes in your client project. They will wrap the classes that comes from the Service and you will be able to make the validation on the client.
On the other hand, if you use WCF RIA Services, you will be able to validate through data annotations as it is described in the last section from the mentioned help article. What is the type of Service that you use ?

All the best,
Petar Mladenov
the Telerik team

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

0
christina noel
Top achievements
Rank 1
answered on 01 Nov 2011, 04:44 PM
Thank you for your suggestions! As I'm using a SOAP (.asmx) service, I can't use the WCF option, but the idea of inheriting a valdiation class from my web service class is working.

For example, my "FileNode" class has a property: Int32? VerticalResolution.
I've created a new class in my Silverlight project like this:  
public class ValidatingFileNode: FileNode    {
            public String ValidVerticalResolution
            {
                get { return VerticalResolution.ToString(); }
                set
                {
                    if(String.IsNullOrEmpty(value))
                    {
                        VerticalResolution = null;
                        return;
                    }
                    Int32 iVal;
                    if(!Int32.TryParse(value,out iVal))
                    {
                       throw new Exception("Value must be an integer.");
                    }
                    if(iVal<0)
                    {
                        throw new Exception("Value must be positive.");
                    }
                    VerticalResolution = iVal;
                }
            }
        }

Then, I bind my form grid to a ValidatingFileNode StaticResource, and use a normal TextBox bound to my new ValidVerticalResolution property:
<TextBox x:Name="numVert" Width="108" Height="20" Text="{Binding ValidVerticalResolution, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"/>

I'm getting the validation errors popping up correctly. And once I'm done I'll be able to use my custom localization manager to properly localize the error strings.

This idea was very helpful! It never occurred to me as a solution to my problem.

--Christina.
0
Petar Mladenov
Telerik team
answered on 04 Nov 2011, 09:09 AM
Hello Christina Noel,

 We are glad to hear that the idea helped. Please let us know if you need further assistance. We would be glad to help you.

Best wishes,
Petar Mladenov
the Telerik team

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

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
christina noel
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
christina noel
Top achievements
Rank 1
Share this question
or