diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/entries.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/entries.js index 8c58aeaa0a5c..ade061e610e8 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/entries.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/entries.js @@ -940,7 +940,7 @@ hqDefine("cloudcare/js/form_entry/entries", [ FileEntry.prototype.constructor = EntrySingleAnswer; FileEntry.prototype.onPreProcess = function (newValue) { var self = this; - if (newValue === "" && self.question.filename()) { + if (newValue === "" && self.question.filename) { self.question.hasAnswered = true; self.fileNameDisplay(self.question.filename()); } else if (newValue !== constants.NO_ANSWER && newValue !== "") { diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js index 0aae5ef20c63..014f17112126 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js @@ -691,13 +691,24 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ element.serverError(null); } - if (allChildren) { - for (let i = 0; i < allChildren.length; i++) { - if (allChildren[i].control >= constants.CONTROL_IMAGE_CHOOSE) { - allChildren[i].filename = element.answer(); + const inputControl = [constants.CONTROL_IMAGE_CHOOSE, constants.CONTROL_LABEL, + constants.CONTROL_AUDIO_CAPTURE, constants.CONTROL_VIDEO_CAPTURE]; + + let findChildAndSetFilename = function (children) { + for (let child of children) { + if (child.children && child.children.length > 0) { + findChildAndSetFilename(child.children); + } else if (inputControl.includes(child.control) && element.binding() === child.binding && + element.ix() === child.ix && element.answer()) { + child.filename = element.answer(); + return; } } + }; + if (allChildren && allChildren.length > 0) { + findChildAndSetFilename(allChildren); } + response.children = allChildren; self.fromJS(response); }