Question T16189
Visible to All Users

Expression formula reference subcomponent questions (self)

created a year ago

Hi!

I have a custom question.

JavaScript
const pacientAge = { name: "pacientage", iconName: "icon-default", title: "Pacient Age", elementsJSON: [ { name: "birthdate", title: "Pacient birth date", type: "inputdate", }, { name: "proceduredate", title: "Procedure date", type: "inputdate", }, { name: "pacientage", title: "Pacient age", type: "expression", }, ], onAfterRender(question, htmlElement) { htmlElement.className += " pacient-age"; }, }; export default pacientAge;

I want to create formula in "pacientage" expression question that references "birthdate" and "proceduredate" values and makes calculations based on their value. How can I reference them?

Screen Shot 2023-12-29 at 10.54.00 AM.png

This is a single complex question.

Answers approved by surveyjs Support

created a year ago

Hello Alexander,
You can use the composite. prefix to reference a question value within the custom component. Consider this example:

JavaScript
const pacientAge = { name: "pacientage", iconName: "icon-default", title: "Pacient Age", elementsJSON: [ { name: "birthdate", title: "Pacient birth date", type: "text", inputType: "date" }, { name: "proceduredate", title: "Procedure date", type: "text", inputType: "date" }, { name: "pacientage", title: "Pacient age", type: "expression", expression: "{composite.birthdate} + ' ' + {composite.proceduredate}" }, ], onAfterRender(question, htmlElement) { htmlElement.className += " pacient-age"; }, };

Please let me know if you have any further questions.

    Comments (1)

      Alexander,
      Take note that SurveyJS Survey Creator and technical support are available under a commercial developer license. Please specify the account which contains an associated developer license.

      Thanks