making ui reference fields readonly or disabled

yundlu316
Kilo Guru

Hi Experts,

I'm building an UI Page with a couple ui reference fields that I want to make readOnly or disabled unless another field has been checked.   I'm trying to do this with javascript:

if (document.getElementById("my_plan").checked){

  document.getElementById('b_plan_name').readOnly = false;

  document.getElementById('b_plan_name').style.backgroundColor   = '#fff' ;

  } else {

  document.getElementById('b_plan_name').readOnly = true;

  document.getElementById('b_plan_name').style.backgroundColor   = '#ddd' ;

  }

This code seems to work with other input fields but does not work with ui reference fields.   Is there a way to do this?  

Thanks!

6 REPLIES 6

If you need to use processing script, then you can use below



var mplan= request.getParameter("my_plan");



Regards,


Sachin



chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi David,



I have tried below example, which may be helpful for you :



HTML:



<g:ui_reference name="assigned_to" table="sys_user" />



Client Script:


function setReadOnlyReference(field_name, flag) {


  if(flag == false)


                  jQuery('#sys_display\\.'+field_name+', #lookup\\.'+field_name+'').removeAttr('disabled');        


    else


                  jQuery('#sys_display\\.'+field_name+', #lookup\\.'+field_name+'').attr('disabled','disabled');


}



For readOnly reference field:


setReadOnlyReference('assigned_to');



For editable :


setReadOnlyReference('assigned_to' , false);