How to make fields readonly using client script based on choice value as No

kavitha N
Tera Contributor

I want to make  calender Date time field readonly based on a condition where a field with choices yes and No is selected as yes using client script

9 REPLIES 9

kavitha N
Tera Contributor

hi team,

i am facing issue with the client script below:

Based on choice field u_additional_peer_review_completed value as yes i need to make the u_additional_peer_review_date' as read only.

u_additional_peer_review_completed field have two choice field values yes ,no.

In the if condition if i am giving as yes  u_additional_peer_review_date this field is not coming as readonly.

Only for no and None u_additional_peer_review_date is displaying as readonly.

please let me know should i need to change anything in my code

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var additional_peer_item= g_form.getValue('u_additional_peer_review_completed');

if(additional_peer_item =='yes')
g_form.setReadonly('u_additional_peer_review_date',true);
else
g_form.setReadonly('u_additional_peer_review_date',false);

//Type appropriate comment here, and begin script below

}

Hi I dont see flower bracket after if and else statement, do like below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var additional_peer_item= g_form.getValue('u_additional_peer_review_completed');

if(additional_peer_item =='yes')
{
g_form.setReadonly('u_additional_peer_review_date',true);
}
else
{
g_form.setReadonly('u_additional_peer_review_date',false);
}

//Type appropriate comment here, and begin script below

}

Regards
Harish

Community Alums
Not applicable

Hi Kavitha,

It means your if part is working you need to check your choice values and configured it correctly.

Hi Kavitha,

I would suggest you to use UI policy instead of Client Script for this requirement as it is easy to use and debug later.

But if anyways you want to use this client script then please make sure you have selected a "Variable Name" because I see your client script is onChange. So you need to define that on what field change you want this client script to run.

 

UtpalDutta_0-1691654568385.png

 

 

If my answer helps then please mark it Helpful or Correct!

 

Thanks,

Utpal

Harish Bainsla
Kilo Patron
Kilo Patron

You can achieve this by ui policy also