Question
Read only fields
I have a code to mark fields on my pdf as read only. I would like 3 of the fields to remain active if they are empty. How do I adjust the code to exclude 3 fields if they are empty?
var currentPageNum = event.target.page;
for (var i = 0; i < this.numFields; i++){
var currentField = this.getField(this.getNthFieldName(i));
if (GetFirstFieldPage(currentField) <= currentPageNum){
currentField.readonly = true;
currentField.display = display.visible;
}
}I tried the changes below, but I couldn't get it to work.
var currentPageNum = event.target.page;
var activeFields = ['field1', 'field2', 'field3']; // Names of the fields that should remain active if empty
for (var i = 0; i < this.numFields; i++) {
var currentField = this.getField(this.getNthFieldName(i));
if (GetFirstFieldPage(currentField) <= currentPageNum) {
var fieldValue = currentField.value;
var isEmptyField = fieldValue === null || fieldValue.trim() === '';
// Check if the field should remain active if it's empty
if (activeFields.includes(currentField.name) && isEmptyField) {
currentField.readonly = false;
currentField.display = display.visible;
} else {
currentField.readonly = true;
currentField.display = display.visible;
}
}
}