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

Tejas Adhalrao
Mega Sage

hi @Kirsten2  ,

First, check whether the script is entering the if condition. Add an alert inside the condition before return false to verify this.

function onSubmit() {
    var answer = g_form.getValue(
        'has_this_request_been_submitted_via_XXXX_s_ai_intake_process'
    );

    if (answer == 'No') {
        alert('Inside No condition. Answer: ' + answer);
        return false;
    }
}

If the alert does not appear, g_form.getValue() may be returning a different value, such as  NO , false , or  0 , instead of No. Jsut Confirm it with alret or log and then use in if condtion.

Check the actual value and update the condition accordingly. Once you confirm the condition is working, you can add the error message and keep return false to prevent submission.

 

Regards,

Tejas

Thank you. I have verified the value is 'No', but it is still ignoring my if statement and submitting.

Ankur Bawiskar
Tera Patron

@Kirsten2 

it means it's unable to compare the value

are you comparing correct value of No OR no?

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Thank you. I have verified the value is 'No', but it is still ignoring my if statement and submitting.