Read Only fields for a Specific View on a form

User393503
Tera Expert

I have a custom view for a location form. I want to make certain fields read-only. Currently, my code are as follows:

 
function onLoad() {
var view = getView('groups_view'); //get viewname

if (view == 'groups_view'){
 
g_form.setReadOnly('short_description', true);
}
}
3 REPLIES 3

Paul Curwen
Giga Sage

I would  advise using a UI Policy for such a requirements it's just easier to do and best practice IMO. But staying with your Client Script on tip is to make sure you have the 'View' field on your Client Script form set to groups_view. That way it will fire when the view is set to groups_view, there no need to code it. 

 

Without doing any of the above though this will also work. Your code should be: 

 

 

 

 

function onLoad() {
var view = getView(); //get viewname
  if (view == 'groups_view'){
     g_form.setReadOnly('short_description', true);
  }
}

 

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @User393503 ,

 

there is a small correction in your code. try

 

var view = getView();

1. Also please check the UI type of your client script it should ALL. and the client script is triggering when the form is loading. (try putting some alerts in your code)

 

2.Also make sure you are using the correct View name. 

 

3.If you the above mentioned points are correct then check if there any UI policies that are conflicting with your client script?

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

Anurag Tripathi
Mega Patron
Mega Patron

You can just add the view here on the client script instead of looking for it

AnuragTripathi_0-1705413716058.png

 

Uncheck the Global flag and view will show up. Add the view name there and then this client script will run only for that view. Same thing works on a ui policy as well.

-Anurag