Skip to content

How to add more properties to ItemValue objects of choices and how to access or reference those additional properties into any expression? #9243

Closed Answered by JaneSjs
kalpadiptyaroy asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @kalpadiptyaroy,
Use the Serializer API and register custom properties for the itemvalue object.

import { Serializer } from "survey-core";

Serializer.addProperties('itemvalue', [
    {name: "price"},
    {name: "country"}
]);

If you use a question name placeholder (e.g., {cars}) in expressions, it will automatically reference a choice's value property.

{
  "type": "text",
  "name": "car-symbol",
  "defaultValueExpression": "{cars}"
}

To access other custom itemvalue attributes, implement a custom function. Consider the following demo: View Plunker.

import { FunctionFactory} from "survey-core";

function getItemValueProp([val, qName, propName]) {
    if (!val || !qName || !propNam…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kalpadiptyaroy
Comment options

Answer selected by JaneSjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants