How to set read only on an CCK autocomplete field

This is how to set an attribute like read only on a CCK autocomplete field programmatically. You have to add a after_build function to execute the below code

<?php
/**
* After build function
*/
function content_log_after_build($form_element, &$form_state){
$form_element['field_l_reference'][0]['nid']['nid']['#attributes']['readonly'] = 'readonly';
}
?>

To style it

input[readonly="readonly"] {
background-color: #EEEEEE;
}
Knowledge keywords: