// Finally Worked
let ticketworkflowconditions = [];
async function loadExistingWorkflowConditions() {
// console.log("Mapping Data for Workflows:", alldata.ticket_workflow_conditions);
// for (const obj of alldata.ticket_workflow_conditions) {
// console.log('Loading rule for event:', eventName);
// await addNewRule(obj);
// }
//thayammal
for (let index = 0; index < ticketworkflowconditions.length; index++) {
const element = ticketworkflowconditions[index];
await addNewRule(null, element, index);
}
}
// Check if the event is unselected or invalid
if (!newEvent) {
console.log("Event unselected or invalid. Resetting ticketworkflowconditions to its initial state.");
code
Assistant
User
when i choose ticket event, why it shows in new line not next to that ?
Assistant
User
Assistant
User
nooo just count on the aleady existing create a div on that number i dont say equal everything\
Assistant
User
Assistant
// Reset ticketworkflowconditions to its initial state
ticketworkflowconditions = [];
// Remove all related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
console.log("ticketworkflowconditions after reset:", ticketworkflowconditions);
return; // Exit early since no further action is needed
}
// Proceed with the existing logic if a valid event is selected
console.log("ticketworkflowconditions in eventSelect", ticketworkflowconditions, newEvent, selectedEvent);
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-3', 'field-name-container');
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-3', 'choices-container');
container.appendChild(choicesContainer);
}
if (obj && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(Removed outer combination from ticketworkflowconditions at index ${ruleIndex});
}
console.log("Delete Event button clicked.");
const eventContainer = container.closest('.event-container');
if (eventContainer) {
const modal = document.getElementById('composition');
if (modal) {
modal.setAttribute('is-open', 'true');
modal.querySelector('fw-modal-title').innerHTML = `<span>Delete Event</span>`;
modal.querySelector('fw-modal-content').innerHTML = `
<span>Are you sure you want to delete this event?</span>
`;
modal.addEventListener(
'fwSubmit',
() => {
eventContainer.remove();
console.log("Event container successfully removed from DOM.");
if (Array.isArray(ticketworkflowconditions)) {
ticketworkflowconditions.splice(ruleIndex, 1);
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions array.`);
} else if (ticketworkflowconditions[ruleIndex]) {
delete ticketworkflowconditions[ruleIndex];
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions object.`);
}
console.log("Updated ticketworkflowconditions:", JSON.stringify(ticketworkflowconditions, null, 2));
showSuccessToast("Event successfully deleted!");
modal.removeAttribute('is-open');
},
{ once: true }
);
}
}
});
function updateIsEnabledState(selectedEventValue, isChecked) {
if (!selectedEventValue) {
console.error("Event is not selected.");
return;
}
let data = {
...ticketworkflowconditions[ruleIndex]
};
ticketworkflowconditions[ruleIndex] = {
...data,
checked: isChecked
};
code
console.log(`Toggle for ${selectedEventValue} set to ${isChecked ? 'enabled' : 'disabled'}.`);
console.log(`Updated ticketworkflowconditions after toggle change: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
deleteButton.addEventListener("click", () => {
console.log(Delete button clicked for mapping at index ${fieldIndex});
const modal = document.getElementById("composition");
if (modal) {
modal.setAttribute("is-open", "true");
modal.querySelector("fw-modal-title").innerHTML = <span>Delete Mapping</span>;
modal.querySelector("fw-modal-content").innerHTML = <span>Are you sure you want to delete this field mapping?</span>;
fieldDropdown.disabled = true;
const findRule = ticketworkflowconditions[ruleIndex];
if (findRule) {
// Ensure the field index is updated rather than appending
findRule.event.combination[fieldIndex] = {
[selectedFieldName]: selectedChoices || [],
};
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
}
} else {
console.error(Field not found in Dropdown for existing mapping: ${selectedFieldName});
}
}
function checkAddButtonVisibility() {
const dropdowns = container.querySelectorAll(".field-name-dropdown");
const selectedFieldValues = Array.from(dropdowns)
.map((dropdown) => dropdown.value)
.filter((value) => value !== "");
code
const areAllFieldsSelected = selectedFieldValues.length >= fields.length;
const lastDropdownWrapper =
dropdowns.length > 0
? dropdowns[dropdowns.length - 1].closest(".button-container")
: null;
if (areAllFieldsSelected) {
console.log("All fields are selected. Hiding Add Button.");
if (addButton.parentNode) {
if (lastDropdownWrapper && lastDropdownWrapper.contains(addButton)) {
lastDropdownWrapper.removeChild(addButton);
}
}
} else {
console.log("Fields are still available. Add Button will be shown.");
if (dropdowns.length > 0 && lastDropdownWrapper) {
if (!lastDropdownWrapper.contains(addButton)) {
lastDropdownWrapper.appendChild(addButton);
addButton.style.visibility = "visible";
}
}
}
addButton.disabled = false;
note : the three div should be wrapped under a div with the counts of col-md-* in field, choices, button.
no mapping issues should be happen.
when i choose a event, that wrapper div inside that fieldds dropdown when i choose field, i get choices. dropdown. now when i click + icon. it should add like this wrapper div inside that field dropdown, choices, butotn same
make changes wherever necessary and give me the full code
To address your requirement of wrapping the new sets of dropdowns (fields, choices, buttons) in a parent <div> that retains the proper column classes, let's modify the existing code appropriately. Here’s the updated code that implements the changes you specified:
Wrapper Div: A new div with the class row field-wrapper wraps the fieldNameContainer, choicesContainer, and buttonContainer to ensure they are aligned.
Add Button Functionality: The Add Button now adds a new set of dropdowns correctly wrapped in the specified structure when clicked.
Event Handling: Reduced redundancy by adding listeners in the appropriate locations to ensure smooth functionality according to the original request.
Maintaining State: Proper management of ticketworkflowconditions array when a new dropdown is added and when resetting choices.
These changes should meet the requirement of adding new dropdowns with the defined structure whenever the + icon is clicked, ensuring that no mapping issues occur. Please integrate the above code into your existing project structure, considering necessary context and possible external dependencies.
If selecting the ticket event creates a new row instead of keeping it adjacent to the existing dropdowns, it likely indicates that the containing elements are not correctly aligned, or the CSS is causing them to stack vertically.
To ensure that the dropdowns for events, fields, choices, and buttons are rendered in a horizontal layout, we need to ensure that the wrapper div has the right classes. The Bootstrap grid system is typically set up for responsive layouts, and we need to make sure that the columns are adequately structured.
Here’s a refined version of the relevant part of your code that ensures dropdowns are aligned side by side:
Updated Code Extract for Aligning Elements
javascript
async function createEventDropdownSet(obj, ruleIndex) {
const newDropdownSet = document.createElement('div');
newDropdownSet.classList.add('row', 'ticketworkflow-dropdown'); // Ensure this has the row class
const eventValue = obj?.event?.eventValue || '';
newDropdownSet.innerHTML = `
<div class="col-md-2 event-name-container">
<fw-select
class="event-name-dropdown"
label="Select Event Name"
required="true"
placeholder="Your choice"
hint-text="Select singular option">
<fw-select-option value="TicketCreate" ${eventValue === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option>
<fw-select-option value="TicketUpdate" ${eventValue === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option>
<fw-select-option value="TicketCreateandUpdate" ${eventValue === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option>
</fw-select>
</div>
`;
newDropdownSet.querySelector('.event-name-dropdown').addEventListener('fwChange', async (event) => {
// Reset the dropdowns if no event is selected
const newEvent = event.target.value;
if (!newEvent) {
ticketworkflowconditions = [];
newDropdownSet.querySelectorAll('.field-wrapper').forEach(wrapper => wrapper.remove());
return;
}
// Add new field/container dropdowns within the same row
await createFieldChoicesButtonWrapper(newDropdownSet, newEvent, ruleIndex);
});
return newDropdownSet;
}
async function createFieldChoicesButtonWrapper(container, selectedEventValue, ruleIndex) {
// Create a new wrapper for field, choices, and button
const wrapperDiv = document.createElement('div');
wrapperDiv.classList.add('row', 'field-wrapper'); // Make sure this element uses 'row' class
const fieldNameContainer = document.createElement('div');
const choicesContainer = document.createElement('div');
const buttonContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-3', 'field-name-container');
choicesContainer.classList.add('col-md-3', 'choices-container');
buttonContainer.classList.add('col-md-2', 'button-container');
buttonContainer.style.marginTop = '20px';
// Append to the wrapper div
wrapperDiv.appendChild(fieldNameContainer);
wrapperDiv.appendChild(choicesContainer);
wrapperDiv.appendChild(buttonContainer);
// Append the wrapper div to the existing container
container.appendChild(wrapperDiv);
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
null, // Reset any selected field names and choices
null,
null,
ruleIndex,
0
);
}
Key Changes
Row Structure: Each set of components (event, fields, choices, buttons) is wrapped in its own row with the row class from Bootstrap. This keeps them horizontally aligned as long as there’s enough width in the container.
Column Classes: Ensure that the columns added (col-md-*) correctly represent the desired width and do not exceed the total available Bootstrap grid width. The Bootstrap grid system is 12 columns. You can only allocate columns that sum to 12 or fewer across the row.
Appending Components: When a new event is selected, it appends the new row of inputs to the container of dropdowns instead of creating a new line.
Additional Considerations
CSS Styles: Make sure no custom CSS is affecting the display of the dropdowns. Inspect the styles applied using browser dev tools to ensure there aren’t any unexpected styles causing elements to stack.
Responsive Design: Keep in mind that as the viewport resizes, the Bootstrap grid system will stack columns if there is not enough horizontal space.
Integrating the changes should allow the dropdowns to display properly next to each other. Please try these adjustments and verify that the layout displays as intended. If issues persist, consider checking for conflicting CSS rules or other JavaScript impacting the layout.
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-3', 'field-name-container');
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-3', 'choices-container');
container.appendChild(choicesContainer);
}
if (obj && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(Removed outer combination from ticketworkflowconditions at index ${ruleIndex});
}
console.log("Delete Event button clicked.");
const eventContainer = container.closest('.event-container');
if (eventContainer) {
const modal = document.getElementById('composition');
if (modal) {
modal.setAttribute('is-open', 'true');
modal.querySelector('fw-modal-title').innerHTML = `<span>Delete Event</span>`;
modal.querySelector('fw-modal-content').innerHTML = `
<span>Are you sure you want to delete this event?</span>
`;
modal.addEventListener(
'fwSubmit',
() => {
eventContainer.remove();
console.log("Event container successfully removed from DOM.");
if (Array.isArray(ticketworkflowconditions)) {
ticketworkflowconditions.splice(ruleIndex, 1);
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions array.`);
} else if (ticketworkflowconditions[ruleIndex]) {
delete ticketworkflowconditions[ruleIndex];
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions object.`);
}
console.log("Updated ticketworkflowconditions:", JSON.stringify(ticketworkflowconditions, null, 2));
showSuccessToast("Event successfully deleted!");
modal.removeAttribute('is-open');
},
{ once: true }
);
}
}
});
function updateIsEnabledState(selectedEventValue, isChecked) {
if (!selectedEventValue) {
console.error("Event is not selected.");
return;
}
let data = {
...ticketworkflowconditions[ruleIndex]
};
ticketworkflowconditions[ruleIndex] = {
...data,
checked: isChecked
};
code
console.log(`Toggle for ${selectedEventValue} set to ${isChecked ? 'enabled' : 'disabled'}.`);
console.log(`Updated ticketworkflowconditions after toggle change: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
what is the total length col-md of fields, choice, and buttons, create a div on that col-md and wrap these three inside that
To ensure that the dropdowns for fields, choices, and buttons are wrapped inside a single div that correctly uses the Bootstrap grid system, you need to calculate the total column classes of the three different sections (fields, choices, and buttons). After calculating, you can create a wrapper div and append the field, choices, and button containers inside it.
Here’s how to modify the initializeEventDropdown function based on your requirement:
Updated initializeEventDropdown Function
javascript
async function initializeEventDropdown(container, obj, ruleIndex) {
console.log("container, obj, ruleIndex", container, obj, ruleIndex);
const eventSelect = container.querySelector('.event-name-dropdown');
const selectedEventValue = eventSelect.value;
console.log(`initializeEventDropdown - Initial selected event: ${selectedEventValue}`);
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
// Create containers if they don't exist
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-4', 'field-name-container'); // Adjusted column size
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-4', 'choices-container'); // Adjusted column size
container.appendChild(choicesContainer);
}
if (!buttonContainer) {
buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-4', 'button-container'); // Adjusted column size
buttonContainer.style.marginTop = '-20px';
container.appendChild(buttonContainer);
}
// Create a wrapper div for fields, choices, and buttons
const wrapperDiv = document.createElement('div');
wrapperDiv.classList.add('row'); // Bootstrap row to hold all
wrapperDiv.appendChild(fieldNameContainer);
wrapperDiv.appendChild(choicesContainer);
wrapperDiv.appendChild(buttonContainer);
// Append the wrapper div to the container
container.appendChild(wrapperDiv);
if (!toggleContainer) {
toggleContainer = document.createElement('div');
toggleContainer.classList.add('col-md-2', 'toggle-container');
toggleContainer.style.position = 'absolute';
toggleContainer.style.right = '5px';
container.style.position = 'relative';
container.appendChild(toggleContainer);
}
toggleContainer.style.display = 'flex';
toggleContainer.style.flexDirection = 'column';
toggleContainer.style.alignItems = 'center';
const toggleSwitch = document.createElement('fw-toggle');
toggleSwitch.setAttribute('size', 'medium');
toggleSwitch.checked = obj ? obj.checked : true;
toggleContainer.appendChild(toggleSwitch);
const deleteButton = document.createElement('fw-button');
deleteButton.textContent = 'Delete Event';
deleteButton.setAttribute('color', 'danger');
deleteButton.style.marginTop = '25px';
toggleContainer.appendChild(deleteButton);
console.log("obj", obj);
if (obj && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(`Removed outer combination from ticketworkflowconditions at index ${ruleIndex}`);
}
updateDropdownAccessibility(toggleSwitch.checked);
toggleSwitch.addEventListener('fwChange', (event) => {
const isChecked = event.target.checked;
updateDropdownAccessibility(isChecked);
updateIsEnabledState(selectedEventValue, isChecked);
});
deleteButton.addEventListener('click', () => {
console.log("Delete Event button clicked.");
const eventContainer = container.closest('.event-container');
if (eventContainer) {
const modal = document.getElementById('composition');
if (modal) {
modal.setAttribute('is-open', 'true');
modal.querySelector('fw-modal-title').innerHTML = `<span>Delete Event</span>`;
modal.querySelector('fw-modal-content').innerHTML = `
<span>Are you sure you want to delete this event?</span>
`;
modal.addEventListener(
'fwSubmit',
() => {
eventContainer.remove();
console.log("Event container successfully removed from DOM.");
if (Array.isArray(ticketworkflowconditions)) {
ticketworkflowconditions.splice(ruleIndex, 1);
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions array.`);
} else if (ticketworkflowconditions[ruleIndex]) {
delete ticketworkflowconditions[ruleIndex];
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions object.`);
}
console.log("Updated ticketworkflowconditions:", JSON.stringify(ticketworkflowconditions, null, 2));
showSuccessToast("Event successfully deleted!");
modal.removeAttribute('is-open');
},
{ once: true }
);
}
}
});
function updateIsEnabledState(selectedEventValue, isChecked) {
if (!selectedEventValue) {
console.error("Event is not selected.");
return;
}
let data = {
...ticketworkflowconditions[ruleIndex]
};
ticketworkflowconditions[ruleIndex] = {
...data,
checked: isChecked
};
console.log(`Toggle for ${selectedEventValue} set to ${isChecked ? 'enabled' : 'disabled'}.`);
console.log(`Updated ticketworkflowconditions after toggle change: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
}
function updateDropdownAccessibility(isChecked) {
const dropdowns = container.querySelectorAll('.choices-dropdown, .field-name-dropdown, .event-name-dropdown');
dropdowns.forEach(dropdown => {
dropdown.disabled = !isChecked;
});
const buttonContainers = container.querySelectorAll('.button-container');
buttonContainers.forEach(buttonContainer => {
const buttons = buttonContainer.querySelectorAll('button, fw-button');
buttons.forEach(button => {
button.disabled = !isChecked;
});
});
}
}
Key Changes Made
Wrapper Div: Added a new wrapperDiv with the class row to hold the three sections (fields, choices, and buttons). This ensures they are aligned horizontally.
Column Sizes: Adjusted the column classes for fieldNameContainer, choicesContainer, and buttonContainer to fit within the Bootstrap grid system. The total column span of the three elements should ideally equal 12. In this example, I've set them to col-md-4, which makes a total of 12 columns (4 + 4 + 4). Adjust these values according to your layout as needed.
Appending the Wrapper: The three containers are now appended to the new wrapperDiv, which is then appended to the container.
This updated structure will keep your controls for fields, choices, and buttons aligned next to each other horizontally while conforming to Bootstrap's column system. Adjust the classes as needed if you require a different layout (like having different widths).
I apologize for the misunderstanding. Let's go through how to dynamically wrap the fieldNameContainer, choicesContainer, and buttonContainer inside a new div that uses a total column count based on the existing column sizes of each.
To clarify, we will:
Dynamically determine the total column size already assigned to fieldNameContainer, choicesContainer, and buttonContainer.
Create a new div with the total column count.
Move the existing containers inside this new wrapper div.
Here's how the initializeEventDropdown function can be updated to achieve this:
Updated initializeEventDropdown Function
javascript
async function initializeEventDropdown(container, obj, ruleIndex) {
console.log("container, obj, ruleIndex", container, obj, ruleIndex);
const eventSelect = container.querySelector('.event-name-dropdown');
const selectedEventValue = eventSelect.value;
console.log(`initializeEventDropdown - Initial selected event: ${selectedEventValue}`);
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
// Create containers if they don't exist
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-4', 'field-name-container'); // Modify as needed
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-4', 'choices-container'); // Modify as needed
container.appendChild(choicesContainer);
}
if (!buttonContainer) {
buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-4', 'button-container'); // Modify as needed
buttonContainer.style.marginTop = '-20px';
container.appendChild(buttonContainer);
}
// Determine the total column length of the three containers
const totalColumnSize = [...container.querySelectorAll('.field-name-container, .choices-container, .button-container')]
.map(el => el.classList.value.match(/col-md-(\d+)/)[1]) // Get the col-md size
.reduce((sum, size) => sum + parseInt(size, 10), 0); // Sum the sizes
// Create a wrapper div with the total column size
const wrapperDiv = document.createElement('div');
wrapperDiv.classList.add('row', `col-md-${totalColumnSize}`); // Set the total size
wrapperDiv.appendChild(fieldNameContainer);
wrapperDiv.appendChild(choicesContainer);
wrapperDiv.appendChild(buttonContainer);
// Clear the container and append the wrapper div
container.innerHTML = ''; // Clear existing contents
container.appendChild(wrapperDiv); // Append the wrapper
// Proceed to create toggle container only if not existing
if (!toggleContainer) {
toggleContainer = document.createElement('div');
toggleContainer.classList.add('col-md-2', 'toggle-container');
toggleContainer.style.position = 'absolute';
toggleContainer.style.right = '5px';
container.style.position = 'relative';
container.appendChild(toggleContainer);
}
toggleContainer.style.display = 'flex';
toggleContainer.style.flexDirection = 'column';
toggleContainer.style.alignItems = 'center';
const toggleSwitch = document.createElement('fw-toggle');
toggleSwitch.setAttribute('size', 'medium');
toggleSwitch.checked = obj ? obj.checked : true;
toggleContainer.appendChild(toggleSwitch);
const deleteButton = document.createElement('fw-button');
deleteButton.textContent = 'Delete Event';
deleteButton.setAttribute('color', 'danger');
deleteButton.style.marginTop = '25px';
toggleContainer.appendChild(deleteButton);
console.log("obj", obj);
if (obj && obj.event.combination && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
// Clean up combination if it exists
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(`Removed outer combination from ticketworkflowconditions at index ${ruleIndex}`);
}
updateDropdownAccessibility(toggleSwitch.checked);
// Event listeners for toggle and delete button...
}
Changes Made
Column Total Calculation: The code gathers the column size using regex to match the col-md-x classes from the existing containers and sums them to get the totalColumnSize.
Dynamic Wrapper Creation: A new wrapperDiv is created with the class row and a dynamic class representing the total column size.
Reinserting Containers: The existing containers for fields, choices, and buttons are appended to the wrapperDiv, and the container is cleared before appending the new layout.
Conclusion
This approach will dynamically create a wrapper around your existing components based on their column classes, allowing for flexible layouts without hardcoding sizes. Adjust the initial portions where the containers are created according to your specific needs or existing codebase.
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-3', 'field-name-container');
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-3', 'choices-container');
container.appendChild(choicesContainer);
}
if (obj && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(Removed outer combination from ticketworkflowconditions at index ${ruleIndex});
}
console.log("Delete Event button clicked.");
const eventContainer = container.closest('.event-container');
if (eventContainer) {
const modal = document.getElementById('composition');
if (modal) {
modal.setAttribute('is-open', 'true');
modal.querySelector('fw-modal-title').innerHTML = `<span>Delete Event</span>`;
modal.querySelector('fw-modal-content').innerHTML = `
<span>Are you sure you want to delete this event?</span>
`;
modal.addEventListener(
'fwSubmit',
() => {
eventContainer.remove();
console.log("Event container successfully removed from DOM.");
if (Array.isArray(ticketworkflowconditions)) {
ticketworkflowconditions.splice(ruleIndex, 1);
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions array.`);
} else if (ticketworkflowconditions[ruleIndex]) {
delete ticketworkflowconditions[ruleIndex];
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions object.`);
}
console.log("Updated ticketworkflowconditions:", JSON.stringify(ticketworkflowconditions, null, 2));
showSuccessToast("Event successfully deleted!");
modal.removeAttribute('is-open');
},
{ once: true }
);
}
}
});
function updateIsEnabledState(selectedEventValue, isChecked) {
if (!selectedEventValue) {
console.error("Event is not selected.");
return;
}
let data = {
...ticketworkflowconditions[ruleIndex]
};
ticketworkflowconditions[ruleIndex] = {
...data,
checked: isChecked
};
code
console.log(`Toggle for ${selectedEventValue} set to ${isChecked ? 'enabled' : 'disabled'}.`);
console.log(`Updated ticketworkflowconditions after toggle change: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
To modify the initializeEventDropdown function as per your requirements, we will count the existing column sizes of fieldNameContainer, choicesContainer, and buttonContainer, and then wrap those containers inside a new div with the total column size.
Here’s how we can implement this:
Calculate the total column size of the existing containers (fieldNameContainer, choicesContainer, and buttonContainer).
Create a new div that encapsulates the total column size and contains the three existing containers.
Append this new total-wrapper div into the existing container.
Updated initializeEventDropdown Function
javascript
async function initializeEventDropdown(container, obj, ruleIndex) {
console.log("container, obj, ruleIndex", container, obj, ruleIndex);
const eventSelect = container.querySelector('.event-name-dropdown');
const selectedEventValue = eventSelect.value;
console.log(`initializeEventDropdown - Initial selected event: ${selectedEventValue}`);
let fieldNameContainer = container.querySelector('.field-name-container');
let choicesContainer = container.querySelector('.choices-container');
let buttonContainer = container.querySelector('.button-container');
let toggleContainer = container.querySelector('.toggle-container');
// Create containers if they don't exist
if (!fieldNameContainer) {
fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-3', 'field-name-container');
container.appendChild(fieldNameContainer);
}
if (!choicesContainer) {
choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-3', 'choices-container');
container.appendChild(choicesContainer);
}
if (!buttonContainer) {
buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container'); // Adjust size if needed
buttonContainer.style.marginTop = '-20px';
container.appendChild(buttonContainer);
}
// Calculate the total column size
const totalColumnSize =
(parseInt(fieldNameContainer.className.match(/col-md-(\d+)/)[1]) || 0) +
(parseInt(choicesContainer.className.match(/col-md-(\d+)/)[1]) || 0) +
(parseInt(buttonContainer.className.match(/col-md-(\d+)/)[1]) || 0);
// Create a wrapper div that will contain all three components
const wrapperDiv = document.createElement('div');
wrapperDiv.classList.add('row', `col-md-${totalColumnSize}`); // Use the total column size
wrapperDiv.appendChild(fieldNameContainer);
wrapperDiv.appendChild(choicesContainer);
wrapperDiv.appendChild(buttonContainer);
// Clear the previous contents and append as a new row
container.innerHTML = ''; // Clears existing contents
container.appendChild(wrapperDiv); // Appending the new wrapper
// Now, create toggle container
if (!toggleContainer) {
toggleContainer = document.createElement('div');
toggleContainer.classList.add('col-md-2', 'toggle-container');
toggleContainer.style.position = 'absolute';
toggleContainer.style.right = '5px';
container.style.position = 'relative';
container.appendChild(toggleContainer);
}
toggleContainer.style.display = 'flex';
toggleContainer.style.flexDirection = 'column';
toggleContainer.style.alignItems = 'center';
const toggleSwitch = document.createElement('fw-toggle');
toggleSwitch.setAttribute('size', 'medium');
toggleSwitch.checked = obj ? obj.checked : true;
toggleContainer.appendChild(toggleSwitch);
const deleteButton = document.createElement('fw-button');
deleteButton.textContent = 'Delete Event';
deleteButton.setAttribute('color', 'danger');
deleteButton.style.marginTop = '25px';
toggleContainer.appendChild(deleteButton);
console.log("obj", obj);
if (obj && obj.event.combination && obj.event.combination.length > 0) {
const fields = obj.event.combination;
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
for (const [fieldName, fieldValue] of Object.entries(element)) {
await fieldschoosingvalues(
selectedEventValue,
fieldNameContainer,
choicesContainer,
buttonContainer,
container,
fieldName,
Array.isArray(fieldValue) ? fieldValue : [fieldValue],
obj,
ruleIndex,
index
);
}
}
}
if (ticketworkflowconditions[ruleIndex] && ticketworkflowconditions[ruleIndex].combination) {
delete ticketworkflowconditions[ruleIndex].combination;
console.log(`Removed outer combination from ticketworkflowconditions at index ${ruleIndex}`);
}
updateDropdownAccessibility(toggleSwitch.checked);
toggleSwitch.addEventListener('fwChange', (event) => {
const isChecked = event.target.checked;
updateDropdownAccessibility(isChecked);
updateIsEnabledState(selectedEventValue, isChecked);
});
deleteButton.addEventListener('click', () => {
console.log("Delete Event button clicked.");
const eventContainer = container.closest('.event-container');
if (eventContainer) {
const modal = document.getElementById('composition');
if (modal) {
modal.setAttribute('is-open', 'true');
modal.querySelector('fw-modal-title').innerHTML = `<span>Delete Event</span>`;
modal.querySelector('fw-modal-content').innerHTML = `
<span>Are you sure you want to delete this event?</span>
`;
modal.addEventListener(
'fwSubmit',
() => {
eventContainer.remove();
console.log("Event container successfully removed from DOM.");
if (Array.isArray(ticketworkflowconditions)) {
ticketworkflowconditions.splice(ruleIndex, 1);
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions array.`);
} else if (ticketworkflowconditions[ruleIndex]) {
delete ticketworkflowconditions[ruleIndex];
console.log(`Event at index ${ruleIndex} successfully removed from ticketworkflowconditions object.`);
}
console.log("Updated ticketworkflowconditions:", JSON.stringify(ticketworkflowconditions, null, 2));
showSuccessToast("Event successfully deleted!");
modal.removeAttribute('is-open');
},
{ once: true }
);
}
}
});
function updateIsEnabledState(selectedEventValue, isChecked) {
if (!selectedEventValue) {
console.error("Event is not selected.");
return;
}
let data = {
...ticketworkflowconditions[ruleIndex]
};
ticketworkflowconditions[ruleIndex] = {
...data,
checked: isChecked
};
console.log(`Toggle for ${selectedEventValue} set to ${isChecked ? 'enabled' : 'disabled'}.`);
console.log(`Updated ticketworkflowconditions after toggle change: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
}
function updateDropdownAccessibility(isChecked) {
const dropdowns = container.querySelectorAll('.choices-dropdown, .field-name-dropdown, .event-name-dropdown');
dropdowns.forEach(dropdown => {
dropdown.disabled = !isChecked;
});
const buttonContainers = container.querySelectorAll('.button-container');
buttonContainers.forEach(buttonContainer => {
const buttons = buttonContainer.querySelectorAll('button, fw-button');
buttons.forEach(button => {
button.disabled = !isChecked;
});
});
}
}
Changes Made:
Calculate Total Column Size: Using regex to match col-md-x from existing containers to calculate their total width.
Wrap in a New div: Created a new wrapperDiv with the total column size using col-md-${totalColumnSize}, and all containers are appended to this wrapper.
Clear Previous Contents: The container is cleared to remove previous HTML elements and only the new layout with the wrapper div is attached.
This setup ensures that the layout remains consistent, maintains responsive design, and uses Bootstrap's grid system properly while accommodating your requirement of dynamically wrapping the elements. Adjust the column counts as necessary based on your specific layout needs.