Asset Builder - Select Field keys


(Emily) #1

Matrix Version: 5.5.2

Hello again brains trust,

I am trying to find a keyword (or modifier) to get my Asset Builder to output a Select metadata field
to print the value (instead of key) in the option tag.
i.e. <option value="ValueText">ValueText</option>
rather than <option value="KeyText">ValueText</option>

I have tried %metadata-F_1234_values% , %metadata-F_field_1234_values% , %metadata-F_1234^as_asset:{various keywords tried here}% … … :exploding_head:

Is there a way I can get it to do what I want?

Why? We have a piece of code which is reading the “value” of the input fields, and then printing it into a preview pane as it is entered. This works for text fields. Our Key is numerical, whilst out Value is text. The Key is also used to represent in a graph, so we need a numerical value as one half of the key/value pair. If I swap the Key to be the text and the value to be numerical, then the Text printed between the Option Tags is the number - not the text (but if this can be altered, I am also OK with that, but changing the “frontend part” does not do this).
(In the mean time, I will get the Javascript code changed to have a varient for the Select options to read the options.text rather than .val – but if it is possible to print is as I originally desire, then I’d still like to know for future!)


(John gill) #2

Unlikely, and even if you could it would prevent the field from being correctly submitted to the Asset Builder.


(Bart Banda) #3

You could get the JSON data of the select field options from the metadata select field asset and perhaps do something with that?

If you are on at least version 5.4.2.0 of Squiz Matrix, you can use the %asset_data% keyword to retrieve these values as an array.

For example, lets say the asset ID of your Metadata select field is 1234 .

You could then use the following keyword format to retrieve the keys and values from each option of the select field like this:

%globals_asset_data_attributes:1234^index:select_options^index:value%

Which would return a value like:

{a: "1", b: "2", c: "3"}

(Emily) #4

Thanks Bart. :slight_smile:
Good to see that piggybacking of an ^index on an ^index works.
I ended up getting out dev to change their JS code to read the .text rather than .val component.
I think the problem using asset_data was that it reads the attributes of the metadata field, rather than the value that the user has selected for the metadata field (i.e. the saved value), so it needed a single value (the selected one) rather than the whole array. The JS was also calculating it pre-submission, on an onChange action from member.

I do love the asset_data keyword though - its quite useful for looking at all the parts I can print out in Asset Listings / etc. :slight_smile: