Not able to remove choice list option from choice field.
This content was last updated in 2023. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 09:36 PM
Hi
i have written a onLoad client script and on based of condition i am removing the choices from choice list field using removeOption() method.
g_form.removeOption(‘state’, 0);
g_form.removeOption(‘state’,2);
etc.
Except one, all choices(which i mentioned in client script) are gettinh removed from field on form.
but the first g_form.removeOption(‘state’,0); is still visible. I don’t know why it’s happening. I checked other UI policy and client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 11:06 PM
Then use value as string.
g_form.removeOption(‘state’, '0');
g_form.removeOption(‘state’,'2');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 10:01 PM
Hi @Jonnie_ ,
Can you please try below 2 solutions:
1. First clear all options with 'g_form.clearOptions('state');' and add required options with 'g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);'.
2. Remove/Disable the options with looping.
var choiceValue='0';
var control = g_form.getControl('state');
var options = control.options;
for (var i = 0; i < options.length; i++) {
var option = options[i];
if (option.value == choiceValue) {
control.options[i].disabled = '';
break;
}
}
I hope this solves your issue.
Mark this as Helpful / Accept the Solution if this clears your issue.
Regards,
Ratnakar