Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Support client side validation for all numeric types #2950

Merged
merged 1 commit into from
Aug 14, 2015

Conversation

ajaybhargavb
Copy link
Contributor

Issue - #2817
Bringing back client side validation support for numeric types from MVC 5.
@dougbu @pranavkm

@pranavkm
Copy link
Contributor

Design looks alright to me. You could add DateTime support as a follow up item.

typeof(short), typeof(ushort),
typeof(int), typeof(uint),
typeof(long), typeof(ulong),
typeof(float), typeof(double), typeof(decimal)

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?

Copy link
Member

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 Types (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.

@dougbu
Copy link
Member

dougbu commented Aug 11, 2015

Design looks fine

@ajaybhargavb ajaybhargavb changed the title [Design] Support client side validation for all numeric types Support client side validation for all numeric types Aug 11, 2015
@ajaybhargavb
Copy link
Contributor Author

Updated.

var type = context.ModelMetadata.ModelType;
var typeToValidate = Nullable.GetUnderlyingType(type) ?? type;

if (_numericTypes.Contains(typeToValidate))
Copy link
Contributor

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

@pranavkm
Copy link
Contributor

@ajaybhargavb
Copy link
Contributor Author

Updated.

{
private const string NumericValidationType = "number";

public ModelClientValidationNumericRule([NotNull] string errorMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc comments

@pranavkm
Copy link
Contributor

Looks :shipit: to me

Assert.Equal(expectedMessage, rule.ErrorMessage);
}

private class Dummy
Copy link
Member

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

@dougbu
Copy link
Member

dougbu commented Aug 12, 2015

⌚ for the missing docs

@ajaybhargavb
Copy link
Contributor Author

Updated.


namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{
public interface IClientModelValidator
{
IEnumerable<ModelClientValidationRule> GetClientValidationRules(ClientModelValidationContext context);
IEnumerable<ModelClientValidationRule> GetClientValidationRules([NotNull] ClientModelValidationContext context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👯

@dougbu
Copy link
Member

dougbu commented Aug 12, 2015

:shipit:

@ajaybhargavb ajaybhargavb force-pushed the client-validation-fix branch from 174b5fa to 30e4b5e Compare August 13, 2015 17:41
@ajaybhargavb ajaybhargavb force-pushed the client-validation-fix branch from 30e4b5e to 4295a57 Compare August 14, 2015 00:38
@ajaybhargavb ajaybhargavb merged commit 4295a57 into dev Aug 14, 2015
@ajaybhargavb ajaybhargavb deleted the client-validation-fix branch August 14, 2015 00:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants