Skip to main content
Known Participant
December 7, 2021
Question

Unable to programmatically undo/remove readonly property on fields

  • December 7, 2021
  • 1 reply
  • 5670 views

Given I have code like the following in Document Javascript:

 

function ReadOnly() {
  var theOption = this.getField("option5");
  var theField = this.getField("text57");
  theField.readonly = !(theOption.value && theOption.value == "Choice1");
}
ReadOnly();



This code will successfully set fields to being read-only, but the opposite doesn't work.  It's as if setting readonly to false doesn't have any effect.

 

Just to make sure, I tried variants of this, such as the following, but it doesn't change the fact that setting a field's readonly property back to false doesn't have any effect. The field stays read-only once the property has been set to true.

 

function ReadOnly() {   
   var theOption = this.getField("option5");
   var theField = this.getField("text57");
   if (theOption.value && theOption.value == "Choix1") {
     theField.readonly = false;
   } else {
     theField.readonly = true;
   }
} 
ReadOnly();
This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
December 7, 2021

Where does you use the script? 

Known Participant
December 7, 2021

The function declaration and the first call are in the Document Javascript section.

I'm also calling ReadOnly() on MouseUp of option5 options.

 

If I console.println(theField.readonly) inside ReadOnly, during and after having changed its value, the value I see in the console corresponds to the state the field should have (e.g. false if I'd like it to be writeable again) but in practice it is not.

Known Participant
December 7, 2021

I even tried simply setting this as the javascript Action on MouseUp of option5:

 

this.getField('text57').readOnly = false;

 

The result is the same, text57 does not become writeable again until I close and re-open the document.