i want to add visible if to last panel in dynamic panel how ?
urgent required also there is a bug when splice a panel the question is not clear out ?
i want to add visible if to last panel in dynamic panel how ?
urgent required also there is a bug when splice a panel the question is not clear out ?
Survey has a pair of events - onDynamicPanelAdded and onDynamicPanelRemoved. You can handle them and update visibility of the elements.
Thanks, Serge
SurveyJS Team
Are you using the removePanelUI method?
Thanks, Serge
SurveyJS Team
no i am using this example https://plnkr.co/edit/DpqFyFynZaOQEQLtFmA0?p=preview
The link you provided doesn't contain panel dynamic.
Thanks, Serge
SurveyJS Team
sorry https://plnkr.co/edit/j3PDXd?p=preview
What's wrong with this sample?
When it remove a panel, corresponding value is removed from data as well:
panel.allowRemovePanel = true; panel.removePanelUI(panel.panels[index]); // remove panel from UI panel.allowRemovePanel = false; employersValue.splice(index, 1); // remove data item
Thanks, Serge
SurveyJS Team
not working for this :
Survey .StylesManager .applyTheme("default"); var json = { "pages": [ { "name": "page1", "title": "Who are you employed by?", "elements": [ { "type": "checkbox", "name": "employer_names", "isRequired": true, "title": "Please select employers", "choices" : ["John Snow", "Ned Stark", "Robert Baratheon", "Theon Greyjoy", "Samwell Tarly"] } , { "name": "page2", "type": "panel", "title": "Tells us about your employer(s)", "elements": [ { "type": "paneldynamic", "renderMode": "list", "allowAddPanel": false, "allowRemovePanel": false, "name": "arrray_employer_info", "title": "Your employers", "valueName": "employers", "templateTitle": "Employer name: {panel.name}", "templateElements": [ { "type": "panel", "name": "panel_mployer_address", "title": "Address", "elements": [ { "type": "text", "name": "employer_address", "valueName": "address", "title": "Address" }, { "type": "text", "name": "employer_phone", "valueName": "phone", "title": "Phone number:" }, { "type": "text", "name": "employer_abn", "valueName": "abn", "title": "ABN" } ] }, { "type": "panel", "name": "panel_employer_role", "title": "What is your role?", "elements": [ { "type": "radiogroup", "choices": [ "Full time", "Part time", "Casual", "Seasonal" ], "name": "employer_role", "title": "Your role", "valueName": "role" } ] }, { "type": "panel", "name": "panel_employer_hours_work", "title": "What hours do you work?", "elements": [ { "type": "text", "inputType": "number", "name": "member_hours_worked", "valueName": "hours_worked", "title": "Hours:" }, { "type": "dropdown", "name": "member_hours_worked_frequency", "title": "Worked Frequency:", "valueName": "hours_worked_frequency", "startWithNewLine": false, "defaultValue": "Year", "choices": ["Day", "Week", "Fortnight", "Month", "Year"] } ] }, { "type": "panel", "name": "panel_employer_income", "title": "What income do you receive?", "elements": [ { "type": "text", "inputType": "number", "name": "employer_income", "valueName": "income", "title": "Income:" }, { "type": "dropdown", "name": "employer_income_frequency", "title": "Income Frequency", "valueName": "income_frequency", "startWithNewLine": false, "defaultValue": "Year", "choices": ["Day", "Week", "Fortnight", "Month", "Year"] } ] } ] } ] } ], "showQuestionNumbers": "off" }]}; window.survey = new Survey.Model(json); function getValueEmployersIndex(employersValue, employerName) { for(var i = 0; i < employersValue.length; i ++) { if(employersValue[i].name == employerName) return i; } return -1; } function removeFromEmployers(employersValue, employerName) { var index = getValueEmployersIndex(employersValue, employerName); if(index > -1) { employersValue.splice(index, 1); } } function addIntoEmployers(employersValue, employerName) { var index = getValueEmployersIndex(employersValue, employerName); if(index < 0) { employersValue.push({name: employerName}); } } survey.onValueChanged.add(function(sender, options){ if(options.name != "employer_names") return; var employersValue = sender.getValue("employers"); var value = options.value; if(!value) value = []; if(!employersValue) employersValue = []; var question = options.question; for(var i = 0; i < question.visibleChoices.length; i ++) { var itemValue = question.visibleChoices[i].value; isChecked = value.indexOf(itemValue) > -1; if(!isChecked) { removeFromEmployers(employersValue, itemValue) } else { addIntoEmployers(employersValue, itemValue) } } sender.setValue("employers", employersValue); }); survey .onComplete .add(function (result) { document .querySelector('#surveyResult') .innerHTML = "result: " + JSON.stringify(result.data); }); $("#surveyElement").Survey({model: survey});
Unfortunately you copied code from my sample with mistakes…
function removeFromEmployers(employersValue, employerName) { // you did not pass panel here - (panel, employersValue, employerName) var index = getValueEmployersIndex(employersValue, employerName); if(index > -1) { panel.allowRemovePanel = true; // so panel is undefined panel.removePanelUI(panel.panels[index]); // remove panel from UI panel.allowRemovePanel = false; employersValue.splice(index, 1); // remove data item employersValue.splice(index, 1); // here you remove data item second time... this line is absent in my sample } }
and in this fragment the code should be the following:
removeFromEmployers(sender.getQuestionByName("arrray_employer_info"), employersValue, itemValue) // here you should find your panel dynamic question
We can give you an idea and advise how to solve your task with the help of SurveyJS library. We can not write a program for you. We support open source SurveyJS project as a gesture of good will. Hope you understand our point.
Thanks, Serge
SurveyJS Team
thanks Serge again you help me alot
its working but after delete it enable remove button i dnt know why the property we are setting is allowRemovePanel="false"
?
This line of code turns remove button off:
panel.allowRemovePanel = false;
Thanks, Serge
SurveyJS Team
By the way you can simply call the
method. In this case you can remove these lines:
panel.allowRemovePanel = true; // so panel is undefined panel.allowRemovePanel = false;
Thanks, Serge
SurveyJS Team
thanks that fixed it atlast also if i want to add a radio group bhelow the top and i want to show only the options that are selected on above checkboxes.
like this "choices": "{employers}"
thanks for the SurevyJS Team.
Hello,
I've prepared a sample for you - https://plnkr.co/edit/u0TURGKIHAEYhkjEdHbN?p=preview
On entering name car radiogroup is filled with cars choices.
Thanks, Serge
SurveyJS Team