surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.03k stars 785 forks source link

Difference expression between two values #7656

Open ilaplain15115 opened 6 months ago

ilaplain15115 commented 6 months ago

Are you requesting a feature, reporting a bug or asking a question?

Asking a question

What is the current behavior?

Current expression is not calculating the difference between pre and post values

What is the expected behavior?

Pressure delta calculation should show the difference between Pre and Post (Pre-Post)

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code

{
 "title": "GitHub",
 "logoPosition": "right",
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "paneldynamic",
     "name": "question4",
     "title": "Question 1",
     "questionCategory": "surveyquestion",
     "templateElements": [
      {
       "type": "matrixdropdown",
       "name": "Pre1",
       "title": "Pressure Machine",
       "hideNumber": true,
       "questionCategory": "surveyquestion",
       "showHeader": false,
       "columns": [
        {
         "name": "Pre.1",
         "cellType": "text",
         "inputType": "number"
        }
       ],
       "choices": [
        1,
        2,
        3,
        4,
        5
       ],
       "cellType": "text",
       "rows": [
        "Enter Pre Value"
       ]
      },
      {
       "type": "matrixdropdown",
       "name": "Post1",
       "startWithNewLine": false,
       "title": "    ",
       "hideNumber": true,
       "questionCategory": "surveyquestion",
       "showHeader": false,
       "columns": [
        {
         "name": "Post.1",
         "cellType": "text",
         "inputType": "number"
        }
       ],
       "horizontalScroll": true,
       "choices": [
        1,
        2,
        3,
        4,
        5
       ],
       "cellType": "text",
       "rows": [
        "Enter Post Value"
       ]
      },
      {
       "type": "expression",
       "name": "question6",
       "title": "Pressure Calculation",
       "hideNumber": true,
       "questionCategory": "surveyquestion",
       "expression": "{row.Pre1} - {row.Post1}"
      }
     ],
     "allowAddPanel": false,
     "allowRemovePanel": false,
     "panelCount": 1
    }
   ]
  }
 ]
}

Specify your

andrewtelnov commented 6 months ago

@ilaplain15115 "row." prefix works for columns in the same row in the same matrix. 1) You have your expression question in the dynamic panel and it means that you have to use "panel." prefix instead of "row." 2) Pre1 and Post1 are matrix dropdowns. They are question value in the format:

{ 
  row1_Value: { column1: column1Value, column2: column2Value, ... }, 
  row2_Value: { column1: column1Value, column2: column2Value } 
}

Our expression question could not perform any arithmetic operations for two values in this format.

Thank you, Andrew