-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support client side validation for all numeric types #2950
Conversation
Design looks alright to me. You could add |
typeof(short), typeof(ushort), | ||
typeof(int), typeof(uint), | ||
typeof(long), typeof(ulong), | ||
typeof(float), typeof(double), typeof(decimal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complex on platforms where possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understand covering float
, double
and decimal
here. But are the remaining Type
s (all of which should result in a type="number"
attribute on the element) necessary? I haven't seen issues validating integers and am wondering what I'm missing.
Design looks fine |
Updated. |
var type = context.ModelMetadata.ModelType; | ||
var typeToValidate = Nullable.GetUnderlyingType(type) ?? type; | ||
|
||
if (_numericTypes.Contains(typeToValidate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just check the types? It's a small set of types and presumably isn't going to grow
⌚ |
Updated. |
{ | ||
private const string NumericValidationType = "number"; | ||
|
||
public ModelClientValidationNumericRule([NotNull] string errorMessage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add doc comments
Looks |
Assert.Equal(expectedMessage, rule.ErrorMessage); | ||
} | ||
|
||
private class Dummy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a more descriptive and less insulting name than Dummy
e.g. IQChallenged
⌚ for the missing docs |
Updated. |
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation | ||
{ | ||
public interface IClientModelValidator | ||
{ | ||
IEnumerable<ModelClientValidationRule> GetClientValidationRules(ClientModelValidationContext context); | ||
IEnumerable<ModelClientValidationRule> GetClientValidationRules([NotNull] ClientModelValidationContext context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👯
|
174b5fa
to
30e4b5e
Compare
30e4b5e
to
4295a57
Compare
Issue - #2817
Bringing back client side validation support for numeric types from MVC 5.
@dougbu @pranavkm