"Confirm" box in client script

Rocky5
Kilo Sage

Hello Devs,

 

I want to show a confirm box when a field value is changed on the form. and When clicked 'ok' on confirmation box, I need to hide the pending reason field. I am using below script. and I see confirm box is populated every time the form is loaded. and if I use "if (isLoading || newValue === '')" in the first line, the pending reason field is never hidden.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue === '') {
        return;
    }
    var answer = confirm('PR will be removed');
    if (newValue == '-5') {
        g_form.setDisplay('pending_reason', true);
        g_form.setMandatory('pending_reason', true);

    } else if (newValue != 5) {
        if (answer == true) {
            g_form.clearValue('pending_reason');
            g_form.setMandatory('pending_reason', false);
            g_form.setDisplay('pending_reason', false);
        }else{
            return false;
        }
    }
}

 

what is wrong in the above script?

 

Thanks in advance.

Rocky.

4 REPLIES 4

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Rocky5 

 

Can you change the script in the below format

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (newValue == '-5') {
        g_form.setDisplay('pending_reason', true);
        g_form.setMandatory('pending_reason', true);
    } else {
        var answer = confirm('PR will be removed');
        if (answer) {
            g_form.clearValue('pending_reason');
            g_form.setMandatory('pending_reason', false);
            g_form.setDisplay('pending_reason', false);
        } else {
// add the functionality you needed
                  }
    }
}

 

Thanks and regards

Sai Venkatesh

 

Hi @SAI VENKATESH ,

 

I tried that no luck. I still see confirm box every time the form loads. Like said earlier if I use this line below line, the pending reason is never hiding.

 if (isLoading || newValue === '') {



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue === '') {
        return;
    }
    if (newValue == '-5') {
        g_form.setDisplay('pending_reason', true);
        g_form.setMandatory('pending_reason', true);

    } else {
        var answer = confirm('PR will be removed');
        if (answer) {
            g_form.clearValue('pending_reason');
            g_form.setMandatory('pending_reason', false);
            g_form.setDisplay('pending_reason', false);
        }else{
            return false;
        }
    }
}
 
Thanks,
Rocky.

Hi @Rocky5 ,

Can you please try this:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == '-5') {
        g_form.setDisplay('pending_reason', true);
        g_form.setMandatory('pending_reason', true);
    } 
    else {
        var answer = confirm('PR will be removed');
        if (answer) {
            g_form.clearValue('pending_reason');
            g_form.setMandatory('pending_reason', false);
            g_form.setDisplay('pending_reason', false);
        } else {
            return false;
        }
    }
}

 

Hi @Nisha15 ,

 

That is the same script I tried earlier. But no luck.

 

thanks,

Rocky.