Onload client script to make filed readonly

Ashutosh Kumar4
Giga Contributor

I wrote client script to make some fields readonly if it is mobile view.

When i tested it on desktop by setting the mobile view it is working fine but when i tested it after connecting to the instance on mobile(handset). it is still showing as editable.

i used the below script:-

 

function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change

if(getView('mobile')){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);

}
}

Its working on desktop in mobile view but not after connecting instance on handset. Below is the screenshot

find_real_file.png

 

 

 

 

 

6 REPLIES 6

Shweta KHAJAPUR
Tera Guru

Hi Ashutosh,

In your script i don't see any code to make below fields Readonly.

1.Maker

2.Checker

3.Tester

Try as below,

 

function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change

if(getView('mobile')){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);
g_form.setReadonly('u_maker',true);
g_form.setReadonly('u_checker',true);
g_form.setReadonly('u_tester',true);

}
}

I don't want to make below fields readonly

1.Maker

2.Checker

3.Tester

It is working fine in the screenshot i pasted above. My concern is that it is not working when i am looking up the same change request on mobile phone.

Since i have given the condition 

if(getView('mobile')){    //setting below fields as readonly only for mobile view

so it should work with mobile view.

Did i missed something?

 

Thanks...!!!

Try to get the view first and then compare it in if condition. I have provided the code below. Plesase check it.

Try with the below code,

function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change
  var view = getView();   
if(view =='mobile'){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);

}
}