-
Notifications
You must be signed in to change notification settings - Fork 26
Custom validator for "differs to" #106
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
Comments
Thanks for sharing! |
Above code doesn't work in some cases, so I updated it. But in the original It's been a while since I did any TypScript, so am unsure. I'd like to use that Is there some way I can access that method from a custom client validator, or should I copy-paste that function into my own code? (It seems very useful to have for any custom validator though, so wondering why it's hidden - anyone know?) |
You're close. If we were to
There's no way to access it now, but I don't mind the idea of just adding Similar to: aspnet-client-validation/src/index.ts Line 39 in 062c843
|
Thanks for the refresher, haven't touched ts in some years! After closer inspection, it seems that function supports the library's internal machinery, but is not useful for reuse. So I've resorted to using the logic from the original library (which is simpler), and updated my code above. It now works in all uses cases. (But I haven't added any tests... I leave that as an exercise for future readers :) ) I suspect ASP.NET Core will soon dump jquery/jquery-validate/jquery-unobtrusive in lieu of this library (I hope so anyway), so at some point it'll be important to make it easy to extend via custom validators. For now though, there are probably enough extension points. Also, the validator I wrote above was fairly complex (as it involved two fields), so it should be good as a starting point for anyone who wants to add custom validators. |
In theory,
Probably not soon. No response to dotnet/aspnetcore#8573 (comment) and that issue was dropped to the Backlog. |
@haacked, @dahlbyk
I needed a custom validator that is the opposite of
[Compare]
, i.e. validates that two inputs differ. My use case was a password change form: new and old passwords must differ. Was very tricky to get it working on both server and client sides.Posting my solution here in case it helps someone else (and for my own future reference! 😆).
DiffersToAttribute.cs
Add to js init scripts:
Example:
If you ever decide to enable the wiki repo, it would be nice to have a page where we can aggregate our custom validators.
Please close this issue once you've seen it.
The text was updated successfully, but these errors were encountered: