Hello folks. I'm running into an issue with the is...
# cfml-general
p
Hello folks. I'm running into an issue with the isValid() function: I can't seem to pass it an argumentCollection. Wondering if it's me doing something wrong, if it's a bug, or if it's intended for... For example, this will not work, complaining about "Too few attributes..."
sArgs = {
type: "email",
value: "<mailto:john@example.com|john@example.com>",
}
dump( isValid(argumentCollection=sArgs) )
b
I'm guessing you're using Lucee based on the trailing comma in your struct (acf would bark at that). https://github.com/lucee/Lucee/blob/541388c2d8b392b5d77fe6fbb766fa2fa104950c/core/src/main/java/lucee/runtime/functions/decision/IsValid.java Maybe I'm wrong but, for it to support argumentCollection, I'd expect to see something like this at the top of each of the above methods:
this.setAttributes(argumentCollection=arguments);
It looks to me like it's just not supported for isValid (in acf or Lucee)
☝🏻 1
p
So the isValid() wouldn't support passing an argumentCollection ? damn...
t
probably because the requiredness of the params varies by
type
b
Doesn't appear that way
p
this sucks. okay, well, thanks guys 🙂
👍 1
b
Too many commas?
sArgs = {
type: "email",
value: "<mailto:john@example.com|john@example.com>"
}
p
had too manu commas just in my example... but same behavior
image.png
Looks like I'll have to write a custom functions that deals with different signature calls to isValid(): isValid(type, value) isValid("range", value, min, max) isValid("regex" or "regular_expression", value, pattern) this is annoying 😞
t
unfortunately CF doesn't support multiple signatures so you would probably have to revert to java
a
I was gonna suggest using the spread operator but that doesn't work either 😕 Which is, IMO a bug in its implementation.
✔️ 1
Works fine with UDFs; not with BIFs. I should not matter.
e
Why not just wrap your Code around a query then you can loop through the results
IE: <cfquery name="getUsers" datasource="mydatasource"> SELECT email FROM users </cfquery> <cfloop query="getUsers"> <cfset email = getUsers.email> <cfset isValidEmail = isValid("email", email)> <cfdump var="#isValidEmail#"> </cfloop> --- Or you could make this a component, or function, include, or just copy and paste this code eveywhere..
a
e
Or just rewrite the code to put the lotion on...er put the args in the virtual basket, <cfloop query="getUsers"> <cfset email = getUsers.email> <cfset args = { type: "email", value: email }> <cfset isValidEmail = isValid(argumentCollection=args)> <cfdump var="#isValidEmail#"> </cfloop>
p
I ended up having to build my own wrapper around isValid():
👍 1
a
You could simplify the logic and understandability of that code if you returned instead of setting that
test
variable and waiting around to the end of the function before returning it. None of the code after setting
test
is run, so no point in hanging around. Seems weird to have a
isValid
-ish function that doesn't actually take parameters too. But hey ho.
👍 2
😅 1
e
Its old school logic back when Java was taught in California, browsers cost MONEY and only a select few had internet. Old school being isBLAH equals a yes or no.