Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when using inside a Joomla website #470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions src/scripts/cf/ConversationalForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HTMLElement> 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 = <HTMLElement> 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: <HTMLFieldSetElement> 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: <HTMLFieldSetElement> 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);
}
}
}
}
Expand Down Expand Up @@ -778,4 +780,4 @@ if(document.readyState == "complete"){
window.addEventListener("load", () =>{
cf.ConversationalForm.autoStartTheConversation();
}, false);
}
}