This topic is locked

How can I use value of an autofill field to hide a section. Evaluate the autofill value.

1/15/2026 14:50:33
ASPRunner.NET General questions
M
MSchell author

These fields are returned to an Add page from an autofill based on a selected employees name.

I have a possible of 10 discipline incenents to return based on an employees history. Each of the 10 has 3 fields embeded in a section.

If an incedent is returned, I want to display the section, if one is not returned I want to hide the section.

Below is a sample of the code I'm trying to use. Currently it hides all the fields with or without data.

When I do an inspect in the browser and try to watch the field values, they show not available

is there a trick to see the value returned from an Autofill field?

Add Page
Javascript OnLoad event

var DISCIPLINE_DT5 = Runner.getControl(pageid, 'DISCIPLINE_DT5');
var DISCIPLINE_DT6 = Runner.getControl(pageid, 'DISCIPLINE_DT6');
// Block for Discipline 5
const dt5 = DISCIPLINE_DT5?.getValue?.();
if (dt5 && dt5.length >= 1) { // Changed 'value' to 'dt5'
pageObj.toggleItem("discipline5", true);
} else {
pageObj.toggleItem("discipline5", false);
}

// Block for Discipline 6
const dt6 = DISCIPLINE_DT6?.getValue?.();
if (dt6 && dt6.length >= 1) { // Changed 'value' to 'dt6'
pageObj.toggleItem("discipline6", true);
} else {
pageObj.toggleItem("discipline6", false);
}

ChatGPT 1/15/2026

It appears that you are trying to control the visibility of sections in an ASPRunner.NET Add page based on the values returned from autofill fields. The code you provided looks mostly correct, but there may be a couple of points to consider to ensure it's working as intended.

Troubleshooting Steps

  1. Check if Autofill Fields are Correctly Populated: You mentioned that the fields show "not available" when you inspect them in the browser. First, ensure that the autofill feature is functioning correctly. You can log the values to the console to see if they are being populated correctly when the page loads.

     console.log("Discipline DT5:", dt5);
    console.log("Discipline DT6:", dt6);

  2. Use Correct Method to Get Value: The way you are trying to get the value seems correct for the ASPRunner.NET controls. However, you should ensure that the getValue() method is being called correctly. If the controls are not fully initialized when you're trying to access them, you may get unexpected results.


  3. Check for Null or Undefined: When checking the values of dt5 and dt6, it's a good practice to check for null or undefined explicitly.

     const dt5 = DISCIPLINE_DT5?.getValue() || null; // Ensure to call getValue()
    const dt6 = DISCIPLINE_DT6?.getValue() || null;

  4. Use the Correct Length Method: You might want to ensure that you are checking the length of the value correctly. If the value is not a string or array, using .length may not work. It’s better to check if the value is truthy:

     if (dt5) {
    pageObj.toggleItem("discipline5", true);
    } else {
    pageObj.toggleItem("discipline5", false);
    }

    if (dt6) {
    pageObj.toggleItem("discipline6", true);
    } else {
    pageObj.toggleItem("discipline6", false);
    }

  5. Debugging: Consider adding console.log statements to inspect the values of dt5 and dt6 before the conditions to ensure you are getting what you expect.



Example Code

Here’s a revised version of your JavaScript code with the suggestions applied:

var DISCIPLINE_DT5 = Runner.getControl(pageid, 'DISCIPLINE_DT5');
var DISCIPLINE_DT6 = Runner.getControl(pageid, 'DISCIPLINE_DT6');

// Block for Discipline 5
const dt5 = DISCIPLINE_DT5?.getValue() || null; // Ensure correct usage of getValue
console.log("Discipline DT5:", dt5); // Debugging statement
if (dt5) { // Check if dt5 has a value
pageObj.toggleItem("discipline5", true);
} else {
pageObj.toggleItem("discipline5", false);
}

// Block for Discipline 6
const dt6 = DISCIPLINE_DT6?.getValue() || null; // Ensure correct usage of getValue
console.log("Discipline DT6:", dt6); // Debugging statement
if (dt6) { // Check if dt6 has a value
pageObj.toggleItem("discipline6", true);
} else {
pageObj.toggleItem("discipline6", false);
}

Conclusion

By following these steps, you should be able to get the sections to show or hide based on the values returned from the autofill fields. If you continue to encounter issues, check to see if there are any JavaScript errors in the console that might affect the execution of your script.