Copy link to clipboard
Copied
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 available in the dropdown box and fill it with "------------------".
The number of "dashes" required to fill the box will change depending on the item selection from the dropdown list. Thanks in advance. Please Help!!!
Copy link to clipboard
Copied
Use this code:
if (event.value!=event.target.defaultValue) {
var selectedText = event.value;
var remainingSpace = 30 - selectedText.length;
var dashes = "-".repeat(remainingSpace);
var filledText = selectedText + dashes;
event.value = filledText;
}
Copy link to clipboard
Copied
Why do you need to calculate it? The values of the drop-down box are fixed, aren't they? Just count how many dashes fit for each value and then hard-code it in your script. Calculating the length of a random string in a (non-monospaced) font is extremely difficult.
Copy link to clipboard
Copied
I apolozize for my shortcommings. I am unable to code it in the way you are instructing.
Copy link to clipboard
Copied
All you need to do is the following:
if (event.value=="Option 1") event.value = "Option 1---------";
else if (event.value=="Option 2") event.value = "Option 2-----------";
else if (event.value=="Option 3") event.value = "Option 3---------------";
etc.
And use it as the field's custom Format script.
Copy link to clipboard
Copied
Is it possible to get a solution by this type of script? Because i have more than 100 items in the dropdown.
var selectedText = event.value;
var maxLength = event.target.fieldFullLength;
var remainingSpace = maxLength - selectedText.length;
var dashes = "-".repeat(remainingSpace);
var filledText = selectedText + dashes;
event.value = filledText;
Copy link to clipboard
Copied
- There's no such property as "fieldFullLength".
- The repeat method will not work in older viewers.
- There's no easy way to calculate the length of a string of non-monospaced fonts.
Copy link to clipboard
Copied
If i use monospaced fonts then also it would not be possible right?
Copy link to clipboard
Copied
It would be much easier... You will just need to know how many characters fit in the area of the drop-down field, and then deduct the length of each string from that value, and fill in the rest with dashes. Basically what your original code tried to do.
Copy link to clipboard
Copied
like this?
var selectedText = event.value;
var remainingSpace = 30 - selectedText.length;
var dashes = "-".repeat(remainingSpace);
var filledText = selectedText + dashes;
event.value = filledText;
Then place it in the dropdowns validation script?
Copy link to clipboard
Copied
Yes, although I would use the Format event, so it doesn't actually change the field's value.
Also, as I wrote earlier, the repeat method will not work on older versions of Acrobat and Reader. Just FYI.
Copy link to clipboard
Copied
Almost to my goal. This code works fine in Custom format option.
var selectedText = event.value;
var remainingSpace = 30 - selectedText.length;
var dashes = "-".repeat(remainingSpace);
var filledText = selectedText + dashes;
event.value = filledText;
But it fills all the blank dropdown when no data is in dropdown. your help is needed to achieve this so that only when there will data only then there will be "------- "up to the whole dropdown leangth.
Copy link to clipboard
Copied
By "blank", do you mean when the default value is selected?
Copy link to clipboard
Copied
Yes. Default value is blank.
Copy link to clipboard
Copied
Use this code:
if (event.value!=event.target.defaultValue) {
var selectedText = event.value;
var remainingSpace = 30 - selectedText.length;
var dashes = "-".repeat(remainingSpace);
var filledText = selectedText + dashes;
event.value = filledText;
}
Copy link to clipboard
Copied
Finally it worked. U are really the generous king of the Acrobat JavaScript API. I cant thank you!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now