- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 10:57 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:05 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:05 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:32 AM - edited 10-31-2023 11:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:34 AM