From 94619bb8892b1e532c1968a0a4f7d611ef78e506 Mon Sep 17 00:00:00 2001 From: fstn Date: Tue, 6 Dec 2022 21:09:06 -0600 Subject: [PATCH] Update ConversationalForm.ts --- src/scripts/cf/ConversationalForm.ts | 42 +++++++++++++++------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/scripts/cf/ConversationalForm.ts b/src/scripts/cf/ConversationalForm.ts index a36510090..46f1bbedc 100644 --- a/src/scripts/cf/ConversationalForm.ts +++ b/src/scripts/cf/ConversationalForm.ts @@ -457,27 +457,29 @@ namespace cf { // find the fieldset, if any.. let isFieldsetValidForCF = (tag: HTMLElement) : boolean => {return tag && tag.tagName.toLowerCase() !== "fieldset" && !tag.hasAttribute("cf-questions")}; - let fieldset: HTMLElement = groups[group][0].domElement.parentNode; - if(fieldset && fieldset.tagName.toLowerCase() !== "fieldset"){ - fieldset = fieldset.parentNode; - if(isFieldsetValidForCF(fieldset)){ - // not a valid fieldset, we only accept fieldsets that contain cf attr - fieldset = null; + if(groups[group][0] && groups[group][0].domElement){ + let fieldset: HTMLElement = groups[group][0].domElement.parentNode; + if(fieldset && fieldset.tagName.toLowerCase() !== "fieldset"){ + fieldset = fieldset.parentNode; + if(isFieldsetValidForCF(fieldset)){ + // not a valid fieldset, we only accept fieldsets that contain cf attr + fieldset = null; + } } - } - const tagGroup: TagGroup = new TagGroup({ - fieldset: fieldset, // <-- can be null - elements: groups[group] - }); - - // remove the tags as they are now apart of a group - for(var i = 0; i < groups[group].length; i++){ - let tagToBeRemoved: InputTag = groups[group][i]; - if(i == 0)// add the group at same index as the the first tag to be removed - tags.splice(tags.indexOf(tagToBeRemoved), 1, tagGroup); - else - tags.splice(tags.indexOf(tagToBeRemoved), 1); + const tagGroup: TagGroup = new TagGroup({ + fieldset: fieldset, // <-- can be null + elements: groups[group] + }); + + // remove the tags as they are now apart of a group + for(var i = 0; i < groups[group].length; i++){ + let tagToBeRemoved: InputTag = groups[group][i]; + if(i == 0)// add the group at same index as the the first tag to be removed + tags.splice(tags.indexOf(tagToBeRemoved), 1, tagGroup); + else + tags.splice(tags.indexOf(tagToBeRemoved), 1); + } } } } @@ -778,4 +780,4 @@ if(document.readyState == "complete"){ window.addEventListener("load", () =>{ cf.ConversationalForm.autoStartTheConversation(); }, false); -} \ No newline at end of file +}