conjointsdt icon indicating copy to clipboard operation
conjointsdt copied to clipboard

A potential quick way to add all the unique fields in Survey flow

Open astroboylrx opened this issue 1 year ago • 0 comments

To populate the unique fields for every attribute and every level, one may take advantage of the browser's Console.

The code example below add fields from "F-1-1" to "F-5-3" and then from "F-1-1-1" to "F-5-2-3" (see also the attached video for demonstration).

const EVENT_OPTIONS = {bubbles: true, cancelable: false, composed: true};
const EVENTS = {
    BLUR: new Event("blur", EVENT_OPTIONS),
    CHANGE: new Event("change", EVENT_OPTIONS),
    INPUT: new Event("input", EVENT_OPTIONS),
}; // this is from https://stackoverflow.com/a/69286377/4009531

for (let k = 1; k <= 15; k++) {
    let i = Math.ceil(k / 3); // Calculate i
    let j = (k % 3); // Calculate j
    if (j === 0) {
        j = 3;
    }
    console.log("F-" + i + "-" + j);

    document.getElementsByClassName("a EDPart")[k].click()
    const inputElement = document.querySelector(".inlineEditor")
    inputElement.value = "F-" + i + "-" + j;
    inputElement.dispatchEvent(EVENTS.INPUT);
    await new Promise(r => setTimeout(r, 250))  // wait a bit
}

for (let n = 1; n <= 30; n++) {
    let i = Math.ceil(n / 6); // Calculate i
    let j = Math.ceil((n % 6) / 3); // Calculate j
    let k = (n % 3); // Calculate k
    if (j == 0) {
        j = 2;
    }
    if (k == 0) {
        k = 3;
    }
    console.log("F-" + i + "-" + j + "-" + k);

    document.getElementsByClassName("a EDPart")[n+15].click()
    const inputElement = document.querySelector(".inlineEditor")
    inputElement.value = "F-" + i + "-" + j + "-" + k;
    inputElement.dispatchEvent(EVENTS.INPUT);
    await new Promise(r => setTimeout(r, 250))  // wait a bit
}

https://github.com/astrezhnev/conjointsdt/assets/3999966/3367d04c-0227-4fb4-9f0e-dc3da3a1d438

astroboylrx avatar Feb 21 '24 08:02 astroboylrx