Set only 3 fields to be editable and the rest to be read-only

I need to modify my code for marking fields on a PDF as read-only so that 3 specific fields remain editable if they are empty. How can I adjust the code to exclude these 3 fields if they contain no input?

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.value == ""){
 currentField.readonly = false;
 currentField.display = display.visible;
    }
  }

Answer №1

Utilize an array to store the names of three specific fields that should remain active even when they are empty:

let currentPageNumber = event.target.page;
let fieldsToKeepActive = ['fieldName1', 'fieldName2', 'fieldName3']; // Names of fields to keep active if empty

for (let index = 0; index < this.numFields; index++) {
  let currentFieldName = this.getField(this.getNthFieldName(index));
  
  if (GetFirstFieldPage(currentFieldName) <= currentPageNumber) {
    let fieldValue = currentFieldName.value;
    let isEmpty = fieldValue === null || fieldValue.trim() === '';
    
    // Check if field should remain active when empty
    if (fieldsToKeepActive.includes(currentFieldName.name) && isEmpty) {
      currentFieldName.readonly = false;
      currentFieldName.display = display.visible;
    } else {
      currentFieldName.readonly = true;
      currentFieldName.display = display.visible;
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Various methods for invoking a function within a React component

I've been exploring a subtle distinction here. Imagine I have a button that triggers a function when clicked. There are two methods I've tried, one incorrect and the other correct. Method A: <Input onChange = {function()}/> Method B: < ...

Ways to assign a value to an input element in AngularJS without impacting its ngModel

JAVASCRIPT: .directive('search', [function () { return { restrict: 'A', link: function (scope, element, attrs) { attrs.$set('placeholder', 'Word...'); console.log(attrs); ...

Graphical user interface already constructed for importing .csv files and inserting information into a MySQL database

Looking for a plugin that can assist me in transferring a .csv file to a mySQL database. Initially, I was planning on creating this functionality myself but I believe that the necessary code may already exist. Below, you will find a detailed description of ...

How can I eliminate HTML elements from a string using JavaScript?

Currently, I am utilizing the rich text editor feature of the primeng library. It automatically converts any text I input into HTML format. However, there are instances when I need to display this content in plain text. Is there a straightforward method in ...

What is the best way to reorganize the switch case in order to invoke methods from a class?

I have a special character called Hero within my game, this Hero inherits characteristics from the Player class and can perform a variety of actions. The majority of these actions are customized to suit the Hero's abilities. class Hero extends Player ...

Leveraging the power of JavaScript and jQuery to identify comparable SELECT choices

My current approach involves utilizing the .filter() method to match the value of an INPUT field (prjName) with an option in a SELECT field (prjList). However, this method only works when there is an exact match for the option text: $("select[title=' ...

retrieving data from the database table

I'm having trouble retrieving specific values from a table. No matter what input I provide, I always get results from both rows. I want to match the input ID with the ID in the table. The code I'm attempting to use can be found in the attached im ...

What makes 'Parsing JSON with jQuery' unnecessary?

Just performed an ajax request with a query and noticed that my response is already in the form of a JavaScript object. When I try to parse the JSON using: var obj = jQuery.parseJSON(response); 'obj' turns out to be null, yet I can directly ac ...

Should I reload the entire table or insert a row manually?

This unique ajax question arises: within a table lies the users' information, displayed based on individual settings and timing. Sometimes, users instantly see the data, other times they must wait for it - their choice determines when it appears. Wha ...

`How to resolve page timeout issue caused by looping when using Response.Redirect?`

Currently, I am in the process of building a page that involves creating a large number of files within a folder. Once the task is completed, I compress the folder into a zip file and provide the client with a download link. To keep track of these files, I ...

Pattern matching: Identify text elements specifically within an HTML tag

I've been experimenting with a text highlighting script. Check out my initial attempt here. Here's the code snippet: http://jsfiddle.net/TPg9p/3/ However, I encountered a problem – it only works with simple strings and not those containing HT ...

Enhance Your Website with HTML and JavaScript

Here is the code snippet I am working with: sTAT **javascript** var acc = document.getElementsByClassName("item-wrapper"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function(){ this.classList.toggle("selected"); this.nextElementS ...

Error occurred while importing Three.js library: "ERR_ABORTED 404 (Not Found)"

I have been working on following a tutorial on the three.js fundamentals page, but I keep encountering an error when trying to import the module. The error message simply states that the file cannot be found, but I am unable to determine the cause. < ...

Dynamic field validation using jQuery

I am currently developing a wizard feature that retrieves employees dynamically from the backend. The employee table is created with a radio input field and then inserted into my HTML code: $.ajax({ method: "get", url: '/fetchEmployees/' ...

Attempting to transmit information from a .php file to a .js file

I'm currently in the process of developing a website that features a dedicated video section. However, I am facing an issue where I need to pass data (the specific video's name) from my index.php file, which is stored in a database, to my scriptz ...

Issues arising when using the "if" statement in mongoose search operations

When I search in MongoDB, I encounter validation issues. If it finds the information I am looking for, it returns the result. However, if it doesn't find anything, it returns an empty document. Here is my code and query in Postman: image exports.searc ...

Incorporating a React component into a vanilla JavaScript document

Currently, I am working on implementing a weather widget using an npm module called . This particular module is based on React components, which is a new territory for me. I have managed to include the CDNs provided by the npm module, but I am struggling ...

What is the best way to include a title and a close button at the top of a menu, before the first item, when a button menu is clicked in material-ui?

One of the challenges I'm facing is adding a title to an icon button menu that contains a checkbox list of menu items. When the user clicks on the icon and opens the dropdown, I want the title to appear at the top of the dropdown along with a close bu ...

Is my approach to reactjs/redux correct? I have some queries regarding the code

Is this code correct? Would you approach writing this code differently? In particular, these sections: A) Email: document.getElementById('email').value, Password: document.getElementById('password').value or using onChange || this.r ...

Achieve seamless integration of PHP function execution with Javascript onClick without the need for page

After delving into my research, it seems like Ajax and/or JQuery may be the way to go for what I'm trying to achieve. However, I wanted to double-check before moving forward in that direction. The task at hand involves using a javascript onclick func ...