return false is still allowing form submission

Kirsten2
Tera Contributor

I have a CI with a question that, when answer is 'No' the form should fail at submission with an alert or error message (I have tried both). Does anyone see why it is submitting even though I have 'return false'?

 

function onSubmit() {
    // Replace 'your_question_name' with the actual internal name of your catalog variable
    var answer = g_form.getValue('has_this_request_been_submitted_via_XXXX_s_ai_intake_process');

    // Check if the answer is 'no' (adjust 'no' to match your variable's actual backend value, e.g., 'false', 'No', or '0')
    if (answer == 'No') {
        // Display alert message to the user
       
       alert('If this request has new or changes to AI functionality and you have not submitted an AI Intake form, you cannot continue with this submission.');
       
        // Return false to halt the form submission
        return false;
    }

}
 
Thanks!
8 REPLIES 8

Ehab Pilloor
Giga Sage

Hi @Kirsten2,

 

Is the Applies to catalog view checked in the client script?

Is the value being fetched correctly? add g_form.addInfoMessage after getValue line to check the value.

Is the alert popping up? If not then the condition isnt being validated.

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

Yes, catalog view is checked. The condition is not being validated and I can't figure out why.

Tanushree Maiti
Tera Patron

Hi @Kirsten2 

 

Could you try this code once?

 

function onSubmit() {
var answer = g_form.getValue('has_this_request_been_submitted_via_XXXX_s_ai_intake_process');
if (answer) {
answer = answer.toString().trim().toLowerCase();
}

if (answer == 'no' || answer == 'false' || answer == '0') {
g_form.addInfoMessage('If this request has new or changes to AI functionality and you have not submitted an AI Intake form, you cannot continue with this submission');
return false;
}

return true;
}

Thank you. It still is not working. I cannot figure out why my condition is not getting validated.