Say I have a list of error messages like so:
fieldname message
--------------------
zip "please enter your zip code"
city "please enter your city"
...
I need to store these name-value pairs in a Coldfusion*8* array/object to make them accessible to a client-side validation function (Jquery).
In Jquery I’m referencing error messages by id, so I need to store both.
What’s the equivalent to this Jquery:
var onErr = [ ["zip","please enter your zip code"], ["city", "please enter your city"] ]
in Coldfusion?
I want to do something like this:
<cfset onErr = createObject("component","errorMsg.cfc")>
and in errorMsg.cfc:
<cfset onErr.zip = "please enter your zip code">
<cfset onErr.city = "please enter your city">
...
// then serialize this for pickup by Jquery validation handler
but not sure if this the best and most handy solution. I also looked at array, but there I can only store ID or message, can I? How about multidimensional arrays?
Thanks for help!
EDIT:
Thanks for all help. Finally fiddled my way through (to the next obstacle :-).
Here is how it works (= I can JSONserialize to object and parse in Jquery):
<cfset allErrMsgs=ArrayNew(2)>
<cfset allErrMsgs[1][1] = "firma">
<cfset allErrMsgs[1][2] = tx_validate_firma>
<cfset allErrMsgs[2][1] = "re_firma">
<cfset allErrMsgs[2][2] = tx_validate_firma>
...
So whenever I get new error message, I only have to append them here in my error log. I create this log as a component on Session Start and whenever a user changes languages:
Thanks again.
You want an array of structures (map or object in other languages):
For serialization use serializeJSON() like so:
Or, if you are doing this by remote access to a function set returnformat=”json”