Question T14433
Visible to All Users

Amount Control

created a year ago

I am in the process of digitizing a survey form using SurveyJS that contains multiple budget lines(1… 13). Within each budget line, there are components, and each component contains categories.

In the form, there is a total amount for the project's budget. Each budget line also has a defined amount, the sum of which must not exceed the total project budget.

The amount defined in each budget line needs to be divided among its components(1… 13). The sum of amounts allocated to each component must not exceed the amount of its budget line.

The amount defined in each component needs to be divided among its categories(1… 13). The sum of amounts allocated to each category must not exceed the amount of its component.

How can this problem be solved? Please suggest a solution.

JSON
{ "title": "Financement v1", "pages": [ { "name": "source_donnees", "elements": [ { "type": "text", "name": "montant_total", "title": "Montant total du financement (USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "nb_ligne_budgetaire", "title": "Nombre de ligne budgétaire", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" } ] }, { "name": "budgetaire_budgetaire1", "elements": [ { "type": "html", "name": "html1", "html": "<h4>Ligne budgétaire 1</h4>" }, { "type": "text", "name": "budgetaire_budgetaire1_montanttotal", "title": "Montant total budgétaire(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire1_nbcomposante", "title": "Nombre de composant", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire1_composante_composante1_montant", "title": "Montant de la composante 1(USD)", "inputType": "number" }, { "type": "text", "name": "budgetaire_budgetaire1_composante_composante1_nbcategorie", "visibleIf": "{budgetaire_budgetaire1_nbcomposante} >= 1", "title": "Nombre de categorie coûts de la composante 1", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire1_compsant13_categorie1_montant", "title": "Montant de la catégorie de coûts 1(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire1_composante_composante13_categorie13_montant", "title": "Montant de la catégorie de coûts 13(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" } ], "visibleIf": "{nb_ligne_budgetaire} >= 1" }, { "name": "budgetaire_budgetaire13", "elements": [ { "type": "html", "name": "html1", "html": "<h4>Ligne budgétaire 13</h4>" }, { "type": "text", "name": "budgetaire_budgetaire13_montanttotal", "title": "Montant total budgétaire(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire13_nbcomposante", "title": "Nombre de composant", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire13_composante_composante1_montant", "title": "Montant de la composante 1(USD)", "inputType": "number" }, { "type": "text", "name": "budgetaire_budgetaire13_composante_composante1_nbcategorie", "visibleIf": "{budgetaire_budgetaire13_nbcomposante} >= 1", "title": "Nombre de categorie coûts de la composante 1", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire13_compsant13_categorie1_montant", "title": "Montant de la catégorie de coûts 1(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" }, { "type": "text", "name": "budgetaire_budgetaire13_composante_composante13_categorie13_montant", "title": "Montant de la catégorie de coûts 13(USD)", "inputType": "number", "min": "0", "minErrorText": "La valeur entrée doit être au moins égale à 0" } ], "visibleIf": "{nb_ligne_budgetaire} >= 13" } ] }

Answers approved by surveyjs Support

created a year ago

Hello,
Thank you for the explanation and a survey JSON. From what I gather, you wish to build a form/survey which can have multiple (up to 13) repeatable sections. Each section may contain a subset of components/fields.
If so, you can try a Dynamic Matrix or Dynamic Panel survey element. With these element types, you can create a single template which may have multiple fields/groups and users will be able to add new rows/panels and repeat each group the required number of times.

If you wish to validate survey results and ensure that the budget value specified for each individual category doesn't exceed the total budget, you can set checkErrorsMode to "onComplete" to let a survey validate questions on completion and use one of the available validation options which better suits your task.

Please let me know if this information helps. Otherwise, I'll assist you further.