I have a requirement whenever click the checkbox the list collector value should populate

sakila
Tera Contributor

I have a requirement whenever i click the checkbox the list collector value should be populate automatically.

for example, if am choosing development checkbox, "Dataware house" list collector value should automatically.

populate .

sakila_1-1722433193884.png

 

 i tried code like 

if (g_form.getValue('staging') == 'true') {

        var arr = [];

        var elements = ['IdcDevelopement', 'Idcstaging'];

 

        if (elements.includes(g_form.getValue('datawarhouse_data_module'))) {

           

            arr.push(g_form.getValue('datawarhouse_data_module'));

        }

        arr.push('Idcstaging');

        g_form.setValue('datawarhouse_data_module', arr.toString());

    }

when i select development and staging checkbox list collector value should populate as IdcDevelopement ,and idcstaging that is working but when i removed development checkbox it is not showing anything (clearing all the value) but expected result should be idcstaging . 

1 ACCEPTED SOLUTION

Priyanka0402
Mega Sage
Mega Sage

Hello @sakila  ,
You can create the array and store all of the selected values in one required field. Here you can use onChange Client script. Below is the code:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    function updateListCollector() {
        var arr = [];
        // Check if 'staging' checkbox is selected
        if (g_form.getValue('staging') == 'true') {
            arr.push('Idcstaging');
        }
        // Check if 'development' checkbox is selected
        if (g_form.getValue('development') == 'true') {
            arr.push('IdcDevelopement');
//You can use as many if conditions as per your requirement.
        }
        g_form.setValue('datawarhouse_data_module', arr.join(','));
    }
    updateListCollector();
}

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards

Priyanka

View solution in original post

1 REPLY 1

Priyanka0402
Mega Sage
Mega Sage

Hello @sakila  ,
You can create the array and store all of the selected values in one required field. Here you can use onChange Client script. Below is the code:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    function updateListCollector() {
        var arr = [];
        // Check if 'staging' checkbox is selected
        if (g_form.getValue('staging') == 'true') {
            arr.push('Idcstaging');
        }
        // Check if 'development' checkbox is selected
        if (g_form.getValue('development') == 'true') {
            arr.push('IdcDevelopement');
//You can use as many if conditions as per your requirement.
        }
        g_form.setValue('datawarhouse_data_module', arr.join(','));
    }
    updateListCollector();
}

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards

Priyanka