There are certain combination of options that will make the link field validation fail when the linkfield is used into a flexifield field.
For example:
- Field = required
- Validate URL = no
- Optional URL = no
- Link title = Optional title
This will make the validation fail if a title is not provided but the URL is.
This is because the code to validate the field tries to compare 0 with the string 'optional'. Unfortunately the string 'optional' is casted to an integer which will be 0. Thus the test always returns true and the message 'At least one title or URL must be entered.' will always be shown.
The solution is to use strict equality operator (===) instead of the normal equality operator (==).
Please find attached a patch that correct the above problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | link_6x_2x-strict_equality_operator_field_validation-885364-8.patch | 596 bytes | dqd |
| options_fix.patch | 391 bytes | dan_liip |
Comments
Comment #1
jarodms commentedI had the same problem and this patch worked great for me. Thanks!
Comment #2
sockah commentedJust ran into this too. Thanks.
Comment #3
jcfiala commentedIf you submit a patch, you should set the status to 'needs review' so I (and other folks) and try your patch and make sure it works! jarodms says it worked for him, and I'm supposing sockah tried it as well? So I'll set it all the way over to reviewed & tested by the community so I can find it next time I'm working on this.
Of course, for real fun, you could make me a simpletest test that shows that your patch does what you say it does, but that's not required. (It is, however, good practice.)
Including this change is going to have to wait until after the big git change-over.
Comment #4
sockah commentedHey JC, I actually just changed the settings to avoid the problem. I can't attest to if the patch worked or not. Sorry I couldn't be more help.
Comment #5
jcfiala commentedThanks for letting me know. That said, I'll poke at this issue this weekend.
Comment #6
kmontyI can confirm the bug and the patch fixes the issue. Any chance of getting it applied?
Comment #7
dqdThanks kmonty for waking up this old horse.
Rerolled patch attached. comitted and pushed to HEAD.
Further Info:
But please read the project page info of link module for further validation issues. There is already an issue to collect and discuss all possible validation scenarios in general. That's why I will mark this one here as fixed without further RTBC, since it is comitted to HEAD. I need all concentration inside the ONE and only discussion to move forward. After a D7 implementation we will provide a D6 backport.
Explanation: There are too many corner cases and validation wishes of users to implement them all serially one after the other. We would have a 40 lines cluttered settings form for validation methods only conflicting each other. I think, the right way is to find a maybe more complex but all embracing configuration method, which lets the admin better decide how and when to validate the url. Including a good description which helps to set it up.