- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:40 AM
Hi All,
In my catalog item I have a list collector, where one of the options is 'other'. I would like to show (and make mandatory) a string field 'other consumer' when this option is selected.
Currently I have a client script, but when I select 'other' the field 'other consumer' does not show:
Here is the condition:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:50 AM
Hi @dev_K
use following script, which is working fine:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get the values from the list collector
var selectedValues = g_form.getValue('consumer_list');
// Check if 'Other' is selected
if (selectedValues.indexOf('Other') !== -1) {
// Show and make mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', true);
g_form.setMandatory('other_consumer', true);
} else {
// Hide and make not mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', false);
g_form.setMandatory('other_consumer', false);
}
}
If you want to check your script, please share here to verify.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
Thank you
rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:45 AM
var selectedValues = g_form.getValue('consumer');
var selectedArray = selectedValues.split(',');
for (var i = 0; i < selectedArray.length; i++) {
if (selectedArray[i] === 'Other') {
g_form.setDisplay('other_consumer', true);
g_form.setMandatory('other_consumer', true);
break; // exit the loop if "Other" is found
} else {
g_form.setDisplay('other_consumer', false);
g_form.setMandatory('other_consumer', false);
}
}
this does not work:/ I still cant see the hidden field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:54 AM
Hi @dev_K
Could you please print the var 'selectedArray' once and check value 'Other' is coming correctly there?
Also add logs in 'IF' condition and check condition working correctly or not.
thank you