Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Validation Attributes #29

Closed
johnmerchant opened this issue Nov 27, 2020 · 5 comments
Closed

Client Validation Attributes #29

johnmerchant opened this issue Nov 27, 2020 · 5 comments

Comments

@johnmerchant
Copy link

ASP.NET MVC has the ability to provide Client-side Model Validation to the browser as data-val-* attributes for usage with jQuery Validation.

It would be fantastic if FairyBread could provide something similar for applications using a SPA stack (GraphQL + React etc.) by exposing the client-side validation attributes from ASP.NET MVC as a Yup Schema for usage with Formik and other form libraries.

@benmccallum
Copy link
Owner

Yep, great suggestion, this is definitely something we wanna add here as a new feature. What you've suggested is along the lines of what @maraisr (FED on our team) and I were thinking I believe.

I'm a bit strapped for time at the moment, but we could start designing it for now.

One thing that this library currently doesn't do though is support the asp.net mvc / ComponentModel attributes. And to be honest, I'm not sure if we should. FluentValidation support was really the goal of this library. With the attributes, it becomes complicated to fire the validation (no such thing as Model.IsValid or whatever it is in an MVC action), and it didn't look 100% easy to abstract out that validation firing last time I looked. What might be easier is a shim between the attributes and FluentValidator, something I thought would've been done previously but I couldn't find anything last look. That way the attributes would be translated into FV world, and its then business as usual here.

@benmccallum
Copy link
Owner

benmccallum commented Dec 2, 2020

Something like this maybe:
https://github.com/andreykarinskiy/System.ComponentModel.Annotations.Validation.FluentValidation

Actually no, that goes the other way, allows use of FV in System.ComponentModel.Annotations.Validation.
Also: https://github.com/andreykarinskiy/System.ComponentModel.Annotations.Validation

@johnmerchant
Copy link
Author

I think we could invoke the adapters from FluentValidation.AspNetCore and translate the data-val-* attributes into a Yup schema. I'd be happy to try putting together a PR to implement this.

@benmccallum
Copy link
Owner

More than happy to accept a PR! Perhaps we could do it as a separate project and deployed nuget package so folks can opt-in to this addition. Maybe do a quick design in here and we can agree on an approach before you get stuck in.

@benmccallum
Copy link
Owner

Consolidating this issue and a few others under #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants