From 8cd165ba49a9eb0e29469df583f5b3f5f5f4359d Mon Sep 17 00:00:00 2001 From: Joel Trepp Date: Sun, 3 Sep 2023 15:49:44 +0200 Subject: [PATCH] checkbox logic --- fetchxml/fetchxml.js | 63 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/fetchxml/fetchxml.js b/fetchxml/fetchxml.js index 12fd7d2..2b3ae3a 100644 --- a/fetchxml/fetchxml.js +++ b/fetchxml/fetchxml.js @@ -1,45 +1,44 @@ +const colField = document.querySelector('.inputCol'); +const input = document.querySelector('.inputarea'); +const btn = document.querySelector('button'); +const checkbox = document.querySelector('.filterCheckbox'); +const output = document.querySelector('.outputarea'); +input.addEventListener("input",generateFetch); +checkbox.addEventListener("click",generateFetch); -function generateFetchXML() { - - const colField = document.querySelector('.inputCol'); - const input = document.querySelector('.inputarea'); - const btn = document.querySelector('button'); - const checkbox = document.querySelector('.filterCheckbox'); - const output = document.querySelector('.outputarea'); - +function generateFetch(filterOption) { //set focus on column field - colField.focus() + //colField.focus() + + const attribute = colField.value.trim(); + const entryString = input.value; - btn.onclick = () => { - const attribute = colField.value.trim(); - const entryString = input.value; + let arr = entryString.split(/\r?\n/); + arr = arr.map((x) => x.trim()); + arr = arr.filter((x) => x.length > 0); - let arr = entryString.split(/\r?\n/); - arr = arr.map((x) => x.trim()); - arr = arr.filter((x) => x.length > 0); + const outputArr = []; - const outputArr = []; + for (const name of arr) { - for (const name of arr) { + let converted = ` ${name}`; + outputArr.push(converted); + }; - let converted = ` ${name}`; - outputArr.push(converted); - }; + //add condition filter - //add condition filter - - outputArr.unshift(``); - outputArr.push('') + outputArr.unshift(``); + outputArr.push(''); - //add filter tags before and after - if (checkbox.checked) { + //add filter tags before and after + if (checkbox.checked) { outputArr.unshift(''); - outputArr.push('') - }; - const outputString = outputArr.join('\n'); + outputArr.push(''); + }; + + const outputString = outputArr.join('\n'); - output.value = outputString; + output.value = outputString; - } -} +} \ No newline at end of file