Dear Support,
When adding a new data field to a file upload question using a widget the value for the new data field is only recorded/saved when the value of the uploaded file has changed but not when I only change the value of the new data field.
- I created a new widget to add a new data field (description) to the file upload question.
- The value for the new data field (description) is only recorded when the upload file has changed.
Question: How do I ensure that when only the value of the new data field (description) has changed this new value is recorded.
See below the afterRender of the widget and attached the new/updated file upload question.
Thanks,
Eric
JavaScriptafterRender: function (question, el) {
var setDescription = false;
var mainDiv = document.createElement("div");
var fileDescription = document.createElement("INPUT");
fileDescription.id = "fileDescription_id";
fileDescription.name = "fileDescription_id";
fileDescription.type = "text";
fileDescription.style.cssText = "background-color: #f9f9f9;";
var fileDescriptionLabel = document.createElement("Label");
fileDescriptionLabel.htmlFor = "fileDescription_id";
fileDescriptionLabel.innerHTML="Description";
mainDiv.appendChild(fileDescriptionLabel);
mainDiv.appendChild(fileDescription);
el.parentElement.insertBefore(mainDiv, el);
// fileDescription.onchange does not have the desired effect to change the question description value
fileDescription.onchange = function () {
for (let index = 0; index < question.value.length; index++) {
question.value[index].description = fileDescription.value;
}
};
var onValueChangedCallback = function () {
if(setDescription == false) {
if(typeof question.value[0].description == 'undefined') {
fileDescription.value = '';
} else {
fileDescription.value = question.value[0].description;
}
setDescription = true;
} else {
for (let index = 0; index < question.value.length; index++) {
question.value[index].description = fileDescription.value;
}
}
for (let index = 0; index < question.value.length; index++) {
if(typeof question.value[index].description == 'undefined') {
question.value[index].description = '';
}
}
}
question.valueChangedCallback = onValueChangedCallback;
},
Hello Eric,
Custom Widgets are basically used within Knockout/jQuery apps. Would you please specify your JavaScript development platform?
Hi Jane,
I am using Knockout.
Eric
Thank you for the clarification, Eric. To help me follow, would you please share a simplified demo which reproduces the issue?
I look forward to your reply.
Hi Jane,
Find the link: Sandbox
In the preview, when uploading a file in the file upload question it will show the description data field. After giving a value to the description data field it will not save this value when completing the survey. How can I save the value for the description data field.
Thanks,
Eric