This repository has been archived by the owner on Dec 21, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUI-1958 Revert AUI-533. Custom rules should not be required.
- Loading branch information
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes a custom rule need to be validated even if the input content is empty.
So the original if was saying validate this field when:
in our specific case, we have many input that have are required only in some case eg: if checkbox a is checked, input b is required. that doesn't work anymore because of this specific change.
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the original change in AUI-533, all custom rules required validation, regardless of the
required
property being set.The reasoning for reverting AUI-533 was:
Custom Rule:
custom_AOL: Value must end in "@aol.com"
required
email
custom_AOL
email
custom_AOL
So on Form (B), we want to still validate
custom_AOL
but we don't want to make it required.But, with the original change, it will be "required". Even if we explicitly handle blank values...
E.g. updated Custom Rule:
custom_AOL: Value must end in "@aol.com" or blank ""
....it will still try to enforce the
email
rule as required ever though we don't want it to be.My suggestion for you is; add
required
to your input (B) and have it's custom validator check checkbox (A). This will work as long as you only have one rule (your custom validator) on the field.3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I quite well understand the original request for this fix as I was the requester from liferay EE. If I stay with your sample:
In the case where the field is empty, I expect that in the form (B) the email validator won't trigger an error as the email validator in itself should not make the field required. But I also expect the custom_AOL validator to be trigered, because it might have to trigger an error because the field is empty.
The suggested solution wouldn't work as making the field required would actually make it required, but that is not what we want. Or maybe I didn't understand the suggestion.
Furthermore, I believe that this drastically change a behaviour that has been there for 4 year and that many application rely on. Worst, I'm not even certain how it got in our application as I couldn't find it in the Liferay patch applied.
Thank you for the fast reply.
Regards,
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s correct
This is incorrect.
Each rule, itself, does not determine if the field gets validated or not, and does not determine if the rule will be executed.
Whether a field gets validated is determined in the
validatable()
method above. When this istrue
, all rules on that field will be executed. It’s all or nothing … and you just got me thinking about therequired
rule. More on that in a sec.We considered this, but felt it better to have the correct (and less restrictive) behavior, rather than continuing to rely on buggy behavior.
You’re right, the
required
rule would execute. This is an oversight on my part. I’m going to create a ticket to allow a “better” dynamicrequired
rule. This is partially implemented but isn’t very useful in it’s current state.This will allow something like:
required: magicFn
email
custom_AOL
Would this give you the flexibility to validate your two conditional fields together?
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might work but there is two consequence with this:
On my side, I doesn't believe that it's a buggy behavior to run a validator on an empty field, as long as it is clear that this is the behavior. Even more when we only talk about custom validator, the user of that feature expected there validator to run at all time. The first time I found out that validators weren't run on empty field, I took a few days to dive inside the liferay code then the aui code to find the existence of the validatable() method. It took that time because it is counterintuitive. What was my intuition is that a validator is run every time the field is focused out and the form is submitted. This is the old behavior.
I think that's taking the problem from the wrong side. Each rules shouldn't determine if the field gets validated. I think every rules should be executed at all time but each rules should be written to work in every case as expected (that being the email validator shouldn't make the field required and other similar case)
On last question about how this updated code got in Liferay as it clearly isn't in the applied patch. Does it come from CDN?
Regards,
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to our team about this issue.
In Portal 6.2/AUI 2.0, we are going to revert back to the AUI-533 behavior, by default, and provide an opt-in property for the correct behavior.
So in Portal 6.2 your custom validators should work, without any changes necessary.
Going forward, we'd like Portal7.0/AUI 3 to default to the correct behavior. You'd need to dynamically determine if the field is required using
required: function (node) { ... },
.Please, let us know your thoughts on this.
To follow up on this fix. Please create a LESA ticket so you can receive the proper patch.
Let them know:
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not answering sooner. The followup on LESA has been done.
I believe that it's a good solution and strategy for the aui3 change.
Thank you for your collaboration.
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, as will.
3315c7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I documented a solution to your use case here:
https://issues.liferay.com/browse/LPS-60587?focusedCommentId=712453&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-712453