-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
"validatePresence on" not updating #193
Comments
From my pov, 1 && 2 are features that some/many users wouldn't want since eagerly displaying error messages would be optically annoying. What do you think? If you really wanted this behaviour, we could try to figure out something, but would have to be implemented on your end. Lmk your thoughts! |
@snewcomer I'm experimenting a bit as I've run into limitations with Perhaps a better example would be an address with streetname, apt number, and postal code. The address is optional, but if the user enters the streetname e.g. for future deliveries, you want apt number and postal code to no longer allow empty. However, if either apt number or postal code had been previously (accidentally) focused, they will stay validated and accepted as empty. They will stay green, and only on form submit will those fields (provided they are given the Now I can hide the apt number and postal code until streetname is no longer empty, but it would be a workaround because the I am open to the possibility that I am misunderstanding the use cases of 'on:'. |
I don't see I'd like to validate presence conditionally. |
@allthesignals Not sure what is the latest trend, but this issue was based on version 2.1.0. The expected |
@Redsandro In response to this issue, if you had a minimal reproduction that I could take a look at, I think we could close this issue once and for all 👍 |
@snewcomer unfortunately I'm not using this currently. The issue was that We can close this, although @allthesignals seems to be looking for exactly this feature. Perhaps these days there's a different approach to achieving conditional precense. |
I've been working on something that could achieve this, but I'm having trouble with the re-validation issue you're seeing. My use case is conditional presence validation but the condition is more specific: it should only validate presence when the value of the This has been a matter of updating these lines to something like this, and it works okay: const hasTargetValues = targets.some((target) => changes[target] || (changes[target] === undefined && content[target]));
const hasMatchingWith = options.withValue && targets.some((target) => (changes[target] || content[target]) === options.withValue);
if ((targets && !hasTargetValues) || !hasMatchingWith) {
return true;
} I forked the original twiddle, updated to the latest ember/addon: https://ember-twiddle.com/40a98999c925a2c81ffe87882585de0f?openFiles=validations.user.js%2C You can see that it's necessary to focus into the conditionally validated field to get it to validate. With input fields, this isn't as much of a problem for the user because they can just click it. It will be confusing but not a disaster. However, if you're showing/hiding the conditional validated field, it's a problem because there's no way to re-validate everything. @snewcomer @Redsandro I'm curious if you can think of an approach to get around this problem? If we can solve it as-is with the addon, that would also help with the extended behavior I'm working towards. Is there some way to get it to re-validate anything specified in EDIT: |
validatePresence({ presence: true, on: 'email' })
Version
2.1.0
This is probably me misunderstanding the behavior of the validator.
Steps to reproduce
Expected Behavior
Empty password validates fine, but
Actual Behavior
Empty password stays valid, focused or not.
Once you type in a password and then remove it again then the validator fails (as expected).
The text was updated successfully, but these errors were encountered: