How to add more properties to ItemValue objects of choices and how to access or reference those additional properties into any expression? #9243
-
Hi, Surveyjs Team, Consider this example for understanding my query. [
{
"type": "dropdown",
"name": "cars",
"choices": [
{
"text": "Jaguar",
"value": "jag",
"price": "4500",
"country": "US"
},
{
"text": "BMW",
"value": "bmw",
"price": "10000",
"country": "IN"
}
]
},
{
"type": "text",
"name": "car-symbol",
"defaultValueExpression": "{cars.value}" // Is it possible? if not how to implement it?
},
{
"type": "text",
"name": "car-price",
"defaultValueExpression": "{cars.price}" // Is it possible? if not how to implement it?
},
{
"type": "text",
"name": "car-country",
"defaultValueExpression": "{cars.country}" // Is it possible? if not how to implement it?
}
] Is there any correct way to this in surveyjs as of now, if yes kindly mention that. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @kalpadiptyaroy,
If you use a question name placeholder (e.g.,
To access other custom
I hope this example helps. Let me know if you have further questions. |
Beta Was this translation helpful? Give feedback.
Hello @kalpadiptyaroy,
Use the Serializer API and register custom properties for the
itemvalue
object.If you use a question name placeholder (e.g.,
{cars}
) in expressions, it will automatically reference a choice'svalue
property.To access other custom
itemvalue
attributes, implement a custom function. Consider the following demo: View Plunker.