Skip to main content
Known Participant
May 3, 2024
Question

Acrobat Javascript

  • May 3, 2024
  • 2 replies
  • 492 views

Advance thanks for reading my post. I just want to set a validation or calculation script for a dropdown box so that after entering data in the box it automatically fill the blank space with "-------" in the dropdown box so that it fills its size. i have tried a script but its not working. 

 

var selectedText = event.value;

var maxLength = event.target.maxLength;

var remainingSpace = maxLength  -selectedText.length;
var dashes = "-".repeat(remainingSpace);

var filledText = selectedText + dashes;

event.value = filledText;
}

this.getField("MyDropdownFieldName").setAction("Validate", "fillWithDashes(event);");

 

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 3, 2024

    Don't post scripts from ChatGPT 99% they will not work.

    You need to explain to us (in details) what you try to achieve?

    elendil84Author
    Known Participant
    May 3, 2024

    I have a dropdown list in acrobat form. I want to achive this that after selection of item from dropdown list it will calculate the blank space in the dropdown box and fill it with "----------".  The number of dashes will change depending on the item selection from the dropdown list. Thanks in advance.

    Participant
    May 3, 2024

    Hello,

    It looks like you’re trying to create a script that will fill the remaining space in a dropdown box with dashes after a selection is made. I noticed a couple of issues with your script that might be causing it not to work as expected.

    function fillWithDashes(event) {
        var selectedText = event.value;
        var maxLength = event.target.fieldFullLength; // Use fieldFullLength instead of maxLength
        var remainingSpace = maxLength - selectedText.length;
        var dashes = "-".repeat(remainingSpace);
        var filledText = selectedText + dashes;
        event.value = filledText;
    }
    
    this.getField("MyDropdownFieldName").setAction("Validate", "fillWithDashes");

    Make sure to replace "MyDropdownFieldName" with the actual name of your dropdown field. Also, note that maxLength property might not exist on the event.target object; instead, you should use fieldFullLength to get the maximum number of characters the field can display.

    Remember to define the fillWithDashes function outside of any other function scope so that it’s globally available for the action to call. If you continue to experience issues, ensure that the field’s properties allow for enough characters to display the dashes as intended. Let me know if you need further assistance!



    elendil84Author
    Known Participant
    May 3, 2024

    Code is not working . i have set a document level function with 

     

    function fillWithDashes(event) {
        var selectedText = event.value;
        var maxLength = event.target.fieldFullLength; // Use fieldFullLength instead of maxLength
        var remainingSpace = maxLength - selectedText.length;
        var dashes = "-".repeat(remainingSpace);
        var filledText = selectedText + dashes;
        event.value = filledText;
    }

     

     

    But  problem is where to place this code.

    this.getField("MyDropdownFieldName").setAction("Validate", "fillWithDashes");

    I have tried in dropdown custom validation. but no success. please help!!!