Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Populate a Read Only field with JavaScript?

JayFogelson2
Contributor III

I'm wondering if there is a way/different syntax to use to populate a text field, that is being made read only with a DDE?

The below works, when the field is not being made read only. 

 

The odd thing is the when I check the value with an alert, such as:

alert($('input[id*="f' + textUserField + 'c"]').val());

It works when it's both editable and read only.

<script type="text/javascript">
var userPermField = 20936;
var textUserField= 20937;


Sys.Application.add_load(function() {
var newUserName = $('div[id*="f' + userPermField + 'c"]').text().trim().replace('Pick','');
$('input[id*="f' + textUserField + 'c"]').val(newUserName);
});
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
13 REPLIES 13

This is in 6.4 SP1.

Thanks.  See how this updated code works.

<script type="text/javascript">
     var textFieldId = 20719;

     Sys.Application.add_load(function() {
          setTextNumericField(textFieldId,'This is a test')
     });

     function setTextNumericField(f,v) {
          var textFieldAttributes = new Array();

          textFieldAttributes.push({
               enabled: true,
               emptyMessage: '',
               validationText: v,
               valueAsString: v,
               minValue: '-9999999999999',
               maxValue:'9999999999999',
               lastSetTextBoxValue: v});

          var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);

          $('input[id*="'+ f +'c"]').val(v);
          $('input[id*="'+ f +'c_ClientState"]').val(textFieldAttributesSerialised);

          //Check to see if the field is read-only
          if($('input[id*="'+ f +'c"]').parent().parent().find('.readOnly')) $('input[id*="'+ f +'c"]').parent().parent().find('.readOnly').text(v);
          csp(event)
     }
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

There was an extra span that contained the text value that wasn't getting populated.

 Advisory Consultant

JayFogelson2
Contributor III

That did the trick - thanks David!

Hi David,
I tried using this code for 6.15 and it seems it does not work.

Similarly, we have a requirement where we create a child record from a parent record, copying different fields values over, and making these fields read only through ACL.

Fields like Text (single line/multi), Date, Cross Reference or Radio Button Values List don't get populated, while Drop-Down Values List fields are successfully populated.
All the above fields are also set to Read Only through ACL. 
Is there another way to set these fields to Read-Only through Custom Object, or maybe an updated version of the script?

Thank you