Comments (10)
Thank you for figuring that out. I guess this sorts my use-case out. I might have to come back later, when I circle back to that story I was working on but for now, I think this covers all the bases and I can configure the debounce if i need to.
from aspnet-client-validation.
Calling isFieldValid()
with prevalidate: false
always checks the latest cached validation result, instead of validating again before returning. So what you're seeing is what I would expect.
I'm not sure if we have a way to trigger validations only for a specific field.
from aspnet-client-validation.
Thank you for the clarification there. It would be worth documenting the behaviour in the readme then perhaps as you'll likely get new users asking this same question anyway.
My JS/TS foo is much weaker than my C# but in the event, there was some interest from my side in possibly doing a PR for adding the functionality to bypass cache for validation optionally, would that be something meaningful for the library to have?
from aspnet-client-validation.
Honestly the behavior of validating the whole form when asking if a single field is valid feels like a bug to me. We don't currently have a way to run validators for a single field, but that's not hard to add.
That would be a breaking change, though. Method was introduced in #8. Thoughts, @haacked?
from aspnet-client-validation.
I think we should probably add a method to validateFormField(element)
I wonder if it validates the whole form just in case there are dependencies. For example, if an element is only required if another field is valid or something like that. Iβm AFK so I canβt look.
from aspnet-client-validation.
@Maverik can you give this PR a try? #77
I think we should probably add a method to
validateFormField(element)
I like this as a counterpart to validateForm
. I called it validateField()
, since we don't use FormField
anywhere.
I wonder if it validates the whole form just in case there are dependencies. For example, if an element is only required if another field is valid or something like that.
Validators don't have access to the validation state of other inputs, so dependencies would be on values of other inputs.
from aspnet-client-validation.
Thank you so much for the quick turn around on this @dahlbyk. I've updated the codepen to use the code from this PR commit 7fe1de0.
I can confirm that the new validateField
works exactly as how I'd expect it to and solves my immediate use-case. I find the isFieldValid
to be still confusing (although I understand its behaviour now and its working as intended). I'm only unsure if isFieldValid
should be reflecting the callback changes as reflected in validateField
.
I've also updated the primary input field under testing to test for two validations to ensure multiple validators get exercised as expected in many production scenarios
You may use my updated pen as a demo test if you like. You can leave the prevalidate off and just trigger changes in the "Required Field". I've updated the sample to reflect the new callback as well as the old callback. Should you push another commit during your test, you can easily call the new commit from pen by updating the git hash in import url.
I'm happy to update the pen once this PR is final if any changes are needed for future readers.
Again, thank you very much for the quick turn around. It's highly appreciated!
from aspnet-client-validation.
I find the
isFieldValid
to be still confusing (although I understand its behaviour now and its working as intended). I'm only unsure ifisFieldValid
should be reflecting the callback changes as reflected invalidateField
.
Sorry, I'm not sure what you mean by this? Are you referring to a mismatch between the return value and the value passed to the callback?
from aspnet-client-validation.
Indeed. From my testing, isFieldValid
still doesn't perform the callback (which validateField
does as expected) as I'd expect it to & the result is still coming back as the cached result from last call I think. Here's a screenshot of what I mean (I'm attaching the screenshot for both prevalidate
cases):
PS: I noticed you updated to a new commit, I've updated pen to pull in latest commit from branch directly now so it's always reflecting your latest work at the point of testing this issue.
from aspnet-client-validation.
A ha! I think you're hitting the debounce. If I comment out the validateField()
then I see the isFieldValid
callback result.
from aspnet-client-validation.
Related Issues (20)
- Disabling validation HOT 6
- How to use with Razor Pages, i.e. using PageRemote attribute and not Remote attribute? HOT 1
- Latest bits are not in dist folder nor jsdelivr HOT 2
- The isValid method throws if the form does not contain any validation attributes HOT 3
- Custom validator for "differs to" HOT 5
- Rescanning dynamic inputs does not detect that they are new HOT 3
- Initial isFieldValid returns true when field is empty and uses required validator. HOT 5
- Required validator differs from MVC validation in allowing bypass by using spaces in value. HOT 7
- Docs for remove validation feature
- Add CDN to documentation HOT 4
- checkbox validation does not work HOT 3
- Calling `validateForm` submits the form in Firefox
- razor pageremote type=post HOT 1
- [Q] Reparse form without using `watch:true` MutationObserver HOT 2
- [Bug] Checkbox validation does not work (verified in demo app) HOT 2
- Should not validate disabled fields HOT 9
- Option to ignore particular fields HOT 1
- Do not validate immediately HOT 8
- Purpose of debounce HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnet-client-validation.