Setting a hidden field value with JSON from Javascript and use update event

Hi community,

I’m quite familiar with updating a hidden input field (using it’s unique ID) & triggering the hidden field’s update event to use the passed value…

But, how do we pass a JSON instead of a single text value (instead of ‘My Value’ in the above jquery snippet)?

JSON like this: { "order1" : {"productid" : "121", "producttype": "metal"}}

I’m able to set the hidden field value from javascript like this JSON.stringify(json_object) but when I assign it to an app-connect variable using the hidden field’s update event, the variable doesn’t become a JSON object.

Any help will be appreciated! Cheers!

The input only can store strings and we currently don’t have a json formatter. To get it working you could create your own custom json formatter.

1 Like

Anyone else experienced this scenario, if so, what did you do? And can anyone help with a custom JSON formatter? Will try it out at my end!

Have you tried working with Keyed Arrays?

Hey @ben looking at the arrays at the moment, and came across Keyed Arrays, so trying to figure out the use case of these. Googling returns nothing, so might be Wappler terminology?

Would use u a keyed array when building a schema if the returned schema looks like this:

expanded:

Would you use a keyed array in the schema for this, or is this just a plain array?

I think that, in PHP, this is called an associative array as per

https://www.studytonight.com/php/associative-arrays#:~:text=Advantages%20of%20Associative%20Array&text=We%20can%20save%20more%20data,of%20the%20car%20as%20value.

Ok, perfect - thank you Ben. Will look into Associative Arrays to learn more.