Suggestion T1778
Visible to All Users

Checkbox Score calculation not working

created 6 years ago (modified 6 years ago)

Hi Serge,

I have one urgent issue to resolve, I am stcuked while calculating score for Checkbox control.

Here is the pluncker example : https://plnkr.co/edit/20U6sdQpOiTxd5ps83dT?p=preview

You can replace radio group with check box, and check its not working. I need to calculate check box values in survey form, for reference I am taking single input, radio group and check box group but not able to get scores of check box control.

Please help me asap!! waiting for your reply.

Answers approved by surveyjs Support

created 6 years ago

Hello,

I've implemented the "collecting custom properties" functionality for calculating e.g. "score" via the https://github.com/surveyjs/surveyjs/commit/cc95d01dc913c09ceed9af6aba6e3ffae0f3fc81 commit.

Necessary code for calculating the overall survey score for all question types can be found here - https://github.com/surveyjs/surveyjs/blob/master/tests/surveytests.ts#L6240-L6540

Thanks, Serge
SurveyJS Team

    Comments (2)

      Thanks a ton Serge,

      I understand that its taking lots of your efforts. I appreciate it very much.

      Actually, I have checked the bit library files but its very complex to understand. Can you please create a pluncker example for the shared JSON and calculation code which I can integrate in my solution. You can take the json which covers all possible questions as shared on the previous thread,

      Its seems you have added dll on solution as per the recent bit commit. Serge, I am very near to get its solution, can you please do this favor for me?

      Waiting for your reply!

        Hello,

        As I wrote earlier, all necessary code for calculating the overall survey score for all question types can be found here - https://github.com/surveyjs/surveyjs/blob/master/tests/surveytests.ts#L6240-L6540
        This unit test case had been written exactly on the data you provided.

        Move it to the onComplete event handler is a basic JavaScript programming task.

        Thanks, Serge
        SurveyJS Team

        created 6 years ago

        Hello,
        check box question value is an array. You should check it differently.

        Here is the updated example.

        Thank you,
        Andrew
        SurveyJS Team

          Other Answers

          created 6 years ago

          Yes Andrew, as I have integrated this tool in my production site which is going to live soon, you can understand my urgency here in order to go live I need to check each control working.

          Please try to help me out with this.

            Show previous comments (4)

              Hello,

              At this moment score calculation is not implemented in the SurveyJS library. All calculations are preformed by your custom code. For some questions calculations hasn't been implemented in your code.

              Thanks, Serge
              SurveyJS Team

                Can you please confirm which question does not support calculations?

                And what code I can use to achieve their calculations…?

                  I believe that at this moment the easiest way to fix it for you is to debug the code of the sample and write additional logic brunches to handle all the scenario.

                  I'd like to inform you that at this moment we're working on a solution that should make score manipulation easy. I'll update this thread immediately in case any news.

                  Thanks, Serge
                  SurveyJS Team

                  created 6 years ago

                  Hi Andrew,

                  I am still facing issue while calculating different controls in survey js. Can you please check the calculations for below given json :

                  var json = {
                  questions: [
                  {
                  "type": "radiogroup",
                  "name": "question3",
                  "score": 5,
                  "id": "sq_154",
                  "choices": [
                  {
                  "value": "item1",
                  "score": 1
                  },
                  {
                  "value": "item2",
                  "score": 2
                  },
                  {
                  "value": "item3",
                  "score": 3
                  }
                  ]
                  },
                  {
                  "type": "comment",
                  "name": "question5",
                  "score": 5,
                  "id": "sq_159"
                  },
                  {
                  "type": "imagepicker",
                  "name": "question7",
                  "score": 5,
                  "id": "sq_161",
                  "choices": [
                  {
                  "value": "lion",
                  "score": 1,
                  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
                  },
                  {
                  "value": "giraffe",
                  "text": "giraffe22",
                  "score": 2,
                  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg"
                  },
                  {
                  "value": "panda",
                  "score": 3,
                  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg"
                  },
                  {
                  "value": "camel",
                  "score": 4,
                  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg"
                  }
                  ]
                  },
                  {
                  "type": "file",
                  "name": "question8",
                  "score": 5,
                  "id": "sq_163",
                  "maxSize": 0
                  },
                  {
                  "type": "multipletext",
                  "name": "question11",
                  "score": 5,
                  "id": "sq_175",
                  "items": [
                  {
                  "name": "text1"
                  },
                  {
                  "name": "text2"
                  }
                  ]
                  },
                  {
                  "type": "panel",
                  "name": "panel1",
                  "elements": [
                  {
                  "type": "radiogroup",
                  "name": "question13",
                  "score": 5,
                  "id": "sq_179",
                  "choices": [
                  {
                  "value": "item1",
                  "score": 1
                  },
                  {
                  "value": "item2",
                  "score": 2
                  },
                  {
                  "value": "item3",
                  "score": 3
                  }
                  ]
                  },
                  {
                  "type": "file",
                  "name": "question12",
                  "score": 5,
                  "id": "sq_178",
                  "maxSize": 0
                  }
                  ]
                  },
                  {
                  "type": "nouislider",
                  "name": "question14",
                  "score": 5,
                  "id": "sq_181"
                  },
                  {
                  "type": "paneldynamic",
                  "name": "question16",
                  "score": 5,
                  "id": "sq_183"
                  },
                  {
                  "type": "editor",
                  "name": "question15",
                  "score": 5,
                  "id": "sq_182"
                  },
                  {
                  "type": "matrixdropdown",
                  "name": "question10",
                  "score": 5,
                  "id": "sq_165",
                  "columns": [
                  {
                  "name": "Column 1"
                  },
                  {
                  "name": "Column 2"
                  },
                  {
                  "name": "Column 3"
                  }
                  ],
                  "choices": [
                  {
                  "value": 1,
                  "score": 1
                  },
                  {
                  "value": 2,
                  "score": 2
                  },
                  {
                  "value": 3,
                  "score": 3
                  },
                  {
                  "value": 4,
                  "score": 4
                  },
                  {
                  "value": 5,
                  "score": 5
                  }
                  ],
                  "rows": [
                  "Row 1",
                  "Row 2"
                  ]
                  },
                  {
                  "type": "matrix",
                  "name": "question9",
                  "id": "sq_164",
                  "columns": [
                  {
                  "value": "Column 1",
                  "score": 1
                  },
                  {
                  "value": "Column 2",
                  "score": 2
                  },
                  {
                  "value": "Column 3",
                  "score": 3
                  }
                  ],
                  "rows": [
                  "Row 1",
                  "Row 2"
                  ]
                  },
                  {
                  "type": "rating",
                  "name": "question6",
                  "score": 5,
                  "id": "sq_160"
                  },
                  {
                  "type": "dropdown",
                  "name": "question4",
                  "score": 5,
                  "id": "sq_157",
                  "choices": [
                  {
                  "value": "item1",
                  "score": 1
                  },
                  {
                  "value": "item2",
                  "score": 2
                  },
                  {
                  "value": "item3",
                  "score": 3
                  }
                  ]
                  },
                  {
                  "type": "text",
                  "name": "question1",
                  "score": 5,
                  "id": "sq_148"
                  },
                  {
                  "type": "checkbox",
                  "name": "question2",
                  "score": 3,
                  "id": "sq_149",
                  "choices": [
                  {
                  "value": "item1",
                  "score": 1
                  },
                  {
                  "value": "item2",
                  "score": 2
                  },
                  {
                  "value": "item3",
                  "score": 3
                  }
                  ]
                  }
                  ]
                  };

                  Andrew please check this json as when I include different types of controls in survey form it stops working and calculation is coming as null, however, the calculation logic should be generic but I am not sure whats wrong here. Please check the calculation with this json file and let me know. I need to get my issue resolve with all aspects of survey calculation.

                  Waiting for your reply, appreciate your co operation and help in this matter.

                  Thanks.

                    Comments (1)

                      Hello,
                      You were going to implement it for radio group and check box initially. Now you are asking to implement this functionality for all questions, including dynamic matrix and dynamic panel, they are complex one. It requires to write a significant amount of time. I would say it is a good new feature that can be probably included into our getPlainData() function.
                      We will discuss this scenario tomorrow.

                      Thank you,
                      Andrew
                      SurveyJS Team

                      created 6 years ago

                      Andrew please check the screen shot : I am selecting shown values but calculations are not coming correct :

                      Clipboard-File-1.png

                      Please help !

                        Comments (1)

                          Yep,
                          Sorry, did not check on -1 in indexOf. Here is the updated plunker

                          Thank you,
                          Andrew
                          SurveyJS Team

                          created 6 years ago (modified 6 years ago)

                          Andrew, can you please try with json :

                          var json = {
                          questions: [{
                          "type": "boolean",
                          "name": "myboolean",
                          "label": "ten",
                          "score": 10
                          },
                          {
                          "type": "text",
                          "name": "question1",
                          "title": "Your Name",
                          "isRequired": true,
                          "score": 15,
                          "id": "sq_148"
                          },

                          {
                          type: "checkbox",
                          name: "myradiogroup",
                          title: "Radio question with the score",
                          colCount: 4,
                          choices: [{
                          value: "one",
                          score: 1
                          }, {
                          value: "two",
                          score: 2
                          }, {
                          value: "three",
                          score: 3
                          }]
                          }, {
                          type: "radiogroup",
                          name: "test",
                          title: "Radio question with the score",
                          colCount: 4,
                          choices: [{
                          value: "one",
                          score: 10
                          }, {
                          value: "two",
                          score: 20
                          }, {
                          value: "three",
                          score: 30
                          }]
                          }]
                          };

                          Here I am taking one single input, one radio group and one check box group but its giving incorrect calculation :(

                          I am not getting correct selected values total count, please help me with this.

                          Waiting for your quick reply.

                            Comments (1)

                              What is wrong with it?