Another approach would be to add a readonly
class to the parent element containing all input or textarea fields that need to be made readonly; and add the following in the css:
.readonly textarea,
.readonly input {
pointer-events: none;
background-color: gray;
}