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.21k stars 815 forks source link

Dynamic Panel: The `maxPanelCount` property stops updating after a few value changes #8865

Closed JaneSjs closed 1 month ago

JaneSjs commented 1 month ago

T19993 - Maximum number of panels doesn't work properly https://surveyjs.answerdesk.io/internal/ticket/details/T19993


A custom maxPanelCountExpression property is registered. The custom expression should update the maxPanelCount setting of a Dynamic Panel.

Survey.Serializer.addProperty("paneldynamic", {
   name: "maxPanelCountExpression",   
   type: "expression",
   category: 'logic',
   onExecuteExpression: (obj, res) => {      
      setTimeout(() => { obj.maxPanelCount = res; }, 100);
   }   
});

const json = {
  "logoPosition": "right",
  "pages": [
    {
      "name": "p1",      
      "elements": [
        {
          "type": "dropdown",
          "name": "d1",
          "choices": [
            "Option1",
            "Option2"
          ]
        },
        {
          "type": "text",
          "name": "t1"
        },
        {
          "type": "paneldynamic",
          "name": "p1",          
          "templateElements": [
            {
              "type": "comment",
              "name": "c1"
            }
          ],
          "panelCount": 1,
          "minPanelCount": 1,
          "maxPanelCountExpression": "iif({d1} ='Option1', iif({t1} >7,2,1),-1)"
        }
      ]
    }
  ] 
}

The maxPanelCount property stops updating after multiple field value changes. Please check the following demo: View Demo.

https://github.com/user-attachments/assets/5b9ed342-d6a2-4b59-afcb-fcdab0de8e0b