From de4dbfcc6fe943e0f6fa4f0ad340f604954d7efd Mon Sep 17 00:00:00 2001 From: Minha Date: Thu, 5 Sep 2024 16:14:20 -0400 Subject: [PATCH 1/7] Remove function call to non function object attribute + search for correct child entry to append filename to --- .../static/cloudcare/js/form_entry/entries.js | 2 +- .../static/cloudcare/js/form_entry/form_ui.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) 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..b33f1d40d884 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,19 @@ 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(); + var findChildAndSetFilename = function (children) { + for (const [_, child] of Object.entries(children)) { + if (child.children && child.children.length > 0) { + findChildAndSetFilename(child.children) + } else if (child.control >= constants.CONTROL_IMAGE_CHOOSE) { + child.filename = element.answer(); } } } + if (allChildren && allChildren.length > 0) { + findChildAndSetFilename(allChildren) + } + response.children = allChildren; self.fromJS(response); } From 74b766df9cde31efeca40fc31ee126e0534df34c Mon Sep 17 00:00:00 2001 From: Minha Date: Mon, 9 Sep 2024 12:16:52 -0400 Subject: [PATCH 2/7] Lint fixes --- .../static/cloudcare/js/form_entry/form_ui.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 b33f1d40d884..f8f282189d5c 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 @@ -692,16 +692,18 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ } var findChildAndSetFilename = function (children) { - for (const [_, child] of Object.entries(children)) { + for (var i = 0; i < children.length; i++) { + var child = children[i]; if (child.children && child.children.length > 0) { - findChildAndSetFilename(child.children) + findChildAndSetFilename(child.children); } else if (child.control >= constants.CONTROL_IMAGE_CHOOSE) { child.filename = element.answer(); + break; } } - } + }; if (allChildren && allChildren.length > 0) { - findChildAndSetFilename(allChildren) + findChildAndSetFilename(allChildren); } response.children = allChildren; From 3bf05014354891be150d9b6f2cc008ce9294f360 Mon Sep 17 00:00:00 2001 From: Minha Date: Mon, 9 Sep 2024 13:46:01 -0400 Subject: [PATCH 3/7] Change function to a let --- corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f8f282189d5c..bc4e36763096 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,7 +691,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ element.serverError(null); } - var findChildAndSetFilename = function (children) { + let findChildAndSetFilename = function (children) { for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.children && child.children.length > 0) { From 399053972481e186ba21d50cf585a07166a46835 Mon Sep 17 00:00:00 2001 From: Minha Date: Mon, 9 Sep 2024 15:37:05 -0400 Subject: [PATCH 4/7] PR suggested changes --- .../static/cloudcare/js/form_entry/form_ui.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 bc4e36763096..27202e1e6526 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,14 +691,16 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ element.serverError(null); } + const inputControl = [constants.CONTROL_IMAGE_CHOOSE, constants.CONTROL_LABEL, + constants.CONTROL_AUDIO_CAPTURE, constants.CONTROL_VIDEO_CAPTURE]; + let findChildAndSetFilename = function (children) { - for (var i = 0; i < children.length; i++) { - var child = children[i]; + for (let child of children) { if (child.children && child.children.length > 0) { findChildAndSetFilename(child.children); - } else if (child.control >= constants.CONTROL_IMAGE_CHOOSE) { + } else if (inputControl.includes(child.control)) { child.filename = element.answer(); - break; + return; } } }; From f85775a47027e1e200434792f8d6fd1ad37c3448 Mon Sep 17 00:00:00 2001 From: Minha Date: Wed, 11 Sep 2024 12:05:07 -0400 Subject: [PATCH 5/7] Add a check to ensure filename is appeneded to the correct input question based on broadcast styles or lack thereof --- .../cloudcare/static/cloudcare/js/form_entry/form_ui.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 27202e1e6526..fe490e61c9a6 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 @@ -694,11 +694,17 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ const inputControl = [constants.CONTROL_IMAGE_CHOOSE, constants.CONTROL_LABEL, constants.CONTROL_AUDIO_CAPTURE, constants.CONTROL_VIDEO_CAPTURE]; + var isBroadcast = false + if (element.style.raw) { + isBroadcast = element.style.raw().includes('broadcast'); + } + 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)) { + } else if (inputControl.includes(child.control) && child.style && + child.style.raw.includes('broadcast') === isBroadcast) { child.filename = element.answer(); return; } From f708664e1fb694bf09d2525c71a9ed10904cbff9 Mon Sep 17 00:00:00 2001 From: Minha Date: Wed, 11 Sep 2024 12:10:33 -0400 Subject: [PATCH 6/7] Lint fix --- corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fe490e61c9a6..78917da0bb51 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 @@ -694,7 +694,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ const inputControl = [constants.CONTROL_IMAGE_CHOOSE, constants.CONTROL_LABEL, constants.CONTROL_AUDIO_CAPTURE, constants.CONTROL_VIDEO_CAPTURE]; - var isBroadcast = false + var isBroadcast = false; if (element.style.raw) { isBroadcast = element.style.raw().includes('broadcast'); } From a32b5b10a36c3f478bd49959fbd6c29dd025a966 Mon Sep 17 00:00:00 2001 From: Minha Date: Mon, 16 Sep 2024 13:56:44 -0400 Subject: [PATCH 7/7] Check that ix and binding matches before assigning filename --- .../cloudcare/static/cloudcare/js/form_entry/form_ui.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 78917da0bb51..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 @@ -694,17 +694,12 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ const inputControl = [constants.CONTROL_IMAGE_CHOOSE, constants.CONTROL_LABEL, constants.CONTROL_AUDIO_CAPTURE, constants.CONTROL_VIDEO_CAPTURE]; - var isBroadcast = false; - if (element.style.raw) { - isBroadcast = element.style.raw().includes('broadcast'); - } - 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) && child.style && - child.style.raw.includes('broadcast') === isBroadcast) { + } else if (inputControl.includes(child.control) && element.binding() === child.binding && + element.ix() === child.ix && element.answer()) { child.filename = element.answer(); return; }