return false; not working in on change Client script

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

    if (g_scratchpad.x == '5 year') {
        var answer = confirm(" are you sure to change long term holding ");
        if (answer == true) {
            g_form.addInfoMessage("long term holding changes to " + newValue);
        } else {
            return false;
        }
    }

}
6 REPLIES 6

shloke04
Kilo Patron

Hi,

I do not think return false will work in an On Change client script.

This works in an On Submit client script where return false is used to abort form submission.

What here you need to do is in Else part, clear out the field value and make it mandatory so that user will not be allowed to proceed with form submission.

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

    if (g_scratchpad.x == '5 year') {
        var answer = confirm(" are you sure to change long term holding ");
        if (answer == true) {
            g_form.addInfoMessage("long term holding changes to " + newValue);
        } else {
            g_form.clearValue('Field Name');
g_form.setMandatory('Field Name',true);
        }
    }

}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

once user hit cancel for confirm , value should return to '5 year'; 

Then update your script as below:

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

    if (g_scratchpad.x == '5 year') {
        var answer = confirm(" are you sure to change long term holding ");
        if (answer == true) {
            g_form.addInfoMessage("long term holding changes to " + newValue);
        } else {
           g_form.setValue('Field Name',oldValue);
        }
    }

}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

hi shloke04,

out of town ,sorry for late reply  

same problem, in  confirm box, if cancel is clicked, then again confirm box came and doesn't vanish until i click ok. although value is not changed but need to fix it.