- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 07:22 AM
We had some conflicts between Client Scripts and UI Policies, so are attempting to make our rules via Client Script. It is mostly working, except one thing. The field we are running the rules again is a choice field with --None-- as an option. There is an onLoad script that hides all of the fields dependent upon the choice in the "u_customer" field. Then we have an onChange running against u_customer. If you change the selection from --None-- to Producer or Consumer, the code runs correctly. However, when you change from Producer or Consumer back to --None--, the fields aren't hidden. We've tried the code (two versions) below:
Version 1:
if(g_form.getValue('u_customer') == 'producer'){
g_form.setDisplay('u_producer_code',true);
g_form.setDisplay('u_life',true);
g_form.setDisplay('u_ltc',true);
g_form.setDisplay('u_annuity',true);
g_form.setDisplay('u_verified_date_of_birth',false);
g_form.setValue('u_verified_date_of_birth',false);
if(g_form.getValue('call_type') !== 'wrong_number' && g_form.getValue('call_type') !== 'hang_up'){
g_form.setMandatory('u_producer_code',true);
}
}
else if(g_form.getValue('u_customer') == 'consumer'){
g_form.setDisplay('u_verified_date_of_birth',true);
g_form.setMandatory('u_producer_code',false);
g_form.setDisplay('u_producer_code',false);
g_form.setDisplay('u_life',false);
g_form.setDisplay('u_ltc',false);
g_form.setDisplay('u_annuity',false);
g_form.setValue('u_producer_code',null);
g_form.setValue('u_annuity',false);
g_form.setValue('u_life',false);
g_form.setValue('u_ltc',false);
}
else {
g_form.setDisplay('u_verified_date_of_birth',false);
g_form.setMandatory('u_producer_code',false);
g_form.setDisplay('u_producer_code',false);
g_form.setDisplay('u_life',false);
g_form.setDisplay('u_ltc',false);
g_form.setDisplay('u_annuity',false);
}
Version 2:
if(g_form.getValue('u_customer') !== 'consumer' && g_form.getValue('u_customer') !== 'producer') {
g_form.setDisplay('u_verified_date_of_birth',false);
g_form.setMandatory('u_producer_code',false);
g_form.setDisplay('u_producer_code',false);
g_form.setDisplay('u_life',false);
g_form.setDisplay('u_ltc',false);
g_form.setDisplay('u_annuity',false);
}
else if(g_form.getValue('u_customer') == 'producer'){
g_form.setDisplay('u_producer_code',true);
g_form.setDisplay('u_life',true);
g_form.setDisplay('u_ltc',true);
g_form.setDisplay('u_annuity',true);
g_form.setDisplay('u_verified_date_of_birth',false);
g_form.setValue('u_verified_date_of_birth',false);
if(g_form.getValue('call_type') !== 'wrong_number' && g_form.getValue('call_type') !== 'hang_up'){
g_form.setMandatory('u_producer_code',true);
}
}
else if(g_form.getValue('u_customer') == 'consumer'){
g_form.setDisplay('u_verified_date_of_birth',true);
g_form.setMandatory('u_producer_code',false);
g_form.setDisplay('u_producer_code',false);
g_form.setDisplay('u_life',false);
g_form.setDisplay('u_ltc',false);
g_form.setDisplay('u_annuity',false);
g_form.setValue('u_producer_code',null);
g_form.setValue('u_annuity',false);
g_form.setValue('u_life',false);
g_form.setValue('u_ltc',false);
}
Neither of these triggers a hide of the fields when --None-- is selected after another option.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 07:51 AM
I think this is the line is not allowing it to trigger -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') { //could you please remove this part newValue === '' and check
return;
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 07:29 AM
If you write onChange script on u_customer, the newValue variable holds the new value in the field
You dont have exclusively query again g_form.getValue();
if(newValue == 'producer') // should work fine
Try to printout the alert statement at the start of onChange script
alert(newValue);
in this way you can know whether the onChange script is triggering when you change to --None--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 07:48 AM
I adjusted the code to use newValue and added an alert for the loop that is supposed to capture result when --None-- and it doesn't alert. It must not recognize "none" as a field change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 07:51 AM
I think this is the line is not allowing it to trigger -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') { //could you please remove this part newValue === '' and check
return;
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 08:05 AM
Thanks, removing the or condition here resolved the issue.