submit false when we didn't select any checkbox or any other field

Sirri
Tera Guru

Hi All,

 

I have requirement in catalog there are three checkbox and one multiline text .

No one field is not mandatory.  but when we submit at one field check box or mutli line text will be add.

If we didn't add then submit false.

 

I have return client submit code. Please let us know if i want to modify anything.

 

Please find the attached documents for your reference.

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Sirri ,

 

Plz find the updated code:

 

function onSubmit() {

    // Get the values of the checkboxes and multiline text field

    var checkbox1 = g_form.getValue('checkbox_field_1');

    var checkbox2 = g_form.getValue('checkbox_field_2');

    var checkbox3 = g_form.getValue('checkbox_field_3');

    var multilineText = g_form.getValue('multiline_text_field');

 

    // Check if at least one checkbox is selected or multiline text field is populated

    if ((checkbox1 === 'true' || checkbox2 === 'true' || checkbox3 === 'true') || multilineText) {

        // At least one field is populated, allow the form submission

        return true;

    } else {

        // None of the fields are populated, prevent form submission and show an error message

        alert('Please populate at least one checkbox or multiline text field before submitting the form.');

        return

false;

    }

 

Thanks,

Danish

 

}

View solution in original post

6 REPLIES 6

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Sirri ,

 

I think for checkboxes u can check for the value is "true" or not because by default if it's uncheck it means the value it has is false. So everytime your if condition will only be satisfied.

 

Thanks,

Danish

 

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Sirri ,

 

Plz find the updated code:

 

function onSubmit() {

    // Get the values of the checkboxes and multiline text field

    var checkbox1 = g_form.getValue('checkbox_field_1');

    var checkbox2 = g_form.getValue('checkbox_field_2');

    var checkbox3 = g_form.getValue('checkbox_field_3');

    var multilineText = g_form.getValue('multiline_text_field');

 

    // Check if at least one checkbox is selected or multiline text field is populated

    if ((checkbox1 === 'true' || checkbox2 === 'true' || checkbox3 === 'true') || multilineText) {

        // At least one field is populated, allow the form submission

        return true;

    } else {

        // None of the fields are populated, prevent form submission and show an error message

        alert('Please populate at least one checkbox or multiline text field before submitting the form.');

        return

false;

    }

 

Thanks,

Danish

 

}

 

Hi@Danish Bhairag2 

Thank you, 

I have small modified in your script that is the multilineText !='' in the if script. All is working fine as expected.

Thank you once again

Hi @Sirri ,

 

Possible to share ur updated script plz.

 

Thanks,

Danish