Need to restrict a list collector field up to 10 choices in on change
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 09:48 PM
Can any one provide the script to restrict the choices to 10 in list collector variable for on change client script.
3 REPLIES 3
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 10:06 PM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 10:43 PM
Hi @sumanth1 ,
Please use this onChange client script, on change field would be the list collector field itself
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var values = g_form.getValue('<list_collector_name>').toString().split(',');
if (values.length > 10) {
alert('Limit exceeded - You can select upto 10 values');
g_form.clearValue('<list_collector_name>');
for (var i = 0; i < 10; i++) {
g_form.setValue('<list_collector_name>', values[i]);
}
return false;
}
}
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 06:43 AM
Modified this script a little to set the correct number of values needed in the field.
var reconstructValues = [];
var curVal = newValue;
values = curVal.split(",");
if (values.length > 10) {
alert('Limit exceeded - You can select upto 10 values only');
g_form.clearValue('<list_collector_name>');
for (var i = 0; i < 10; i++) {
reconstructValues.push(values[i]);
}
g_form.setValue('<list_collector_name>', reconstructValues);
}