Question T2527
Visible to All Users

Access Custom Properties in Expressions

created 5 years ago

Hi,

Is there any possibility to access custom properties on checkbox/radiogroup choices?

I want to add a 'price' property to any choices. If the user changes a value it should calculate automatically
the sum of all selected values on all questions.
Can I do that with expressions or an custom function?

I started with an example here

Maybe you can help me with this case?

Thanks in advance! :)
Patrick

Answers approved by surveyjs Support

created 5 years ago

Hello Patrick,
You can do it by using the custom function functionality. Here is the example that does almost the same that you need.

Thank you,
Andrew
SurveyJS Team

    Comments (1)

      You should modify the following code in getPrice function:

      JavaScript
      var question = !!this.row ? this .row .getQuestionByColumnName(params[0]) : null; ...

      ->

      JavaScript
      var question = this.survey.getQuestionByName(params[0]); ...

      Thank you,
      Andrew
      SurveyJS Team

      Other Answers

      created 5 years ago (modified 5 years ago)

      Hey Andrew,

      the selectedItem property doesnt exists here:

      JavaScript
      var question = this.survey.getQuestionByName(params[0]); //get the selected item/choice var selItem = question.selectedItem;

      I get the question object, but no selectedItem property.
      Can you help again? :)

        Show previous comments (2)

          Patrick,
          I do not understand the requirements for hiding choices in radiobox/checkbox. You can use custom function in all expressions/conditions, including choicesVisibleIf property. Could you tell me more about your scenario? Right now, I could not suggest anything since I do not understand what you are trying to achieve.

          Thank you,
          Andrew
          SurveyJS Team

          P P
          PatrickSchneider 5 years ago

            Hey Andrew,

            sorry for my inaccurate description.
            I was looking for a visual component to define the "choicesVisibleIf" values of a question.
            But I see that this already exists in the SurveyJs Creator in the options section of a question.
            Clipboard-File-1.png

            Clipboard-File-2.png

            So everything is cool now :)
            Thank you.

              Great! :)

              Thank you,
              Andrew
              SurveyJS Team