Copy link to clipboard
Copied
Hi,
I am looking for resizing automatically the height of a field according to the number of lines with the fieldFull method.
Here is the script I tryed:
if (event.fieldFull) {
//app.alert("The text field is full.\rWe are going to increase its height to be able to continue typing.");
var nomChamp=event.target.name;
this.resetForm([nomChamp]); // Reset field to lose focus
var aRect=event.target.rect;
aRect[3]=aRect[3]-event.target.textSize*1.16;
event.target.rect=aRect;
event.change=event.changeEx;
this.getField(nomChamp).setFocus();
}
That works approximatly because I lose the focus of the field and I need to type on this field to continue typing... Is there a way to avoid that?
P.S.: The 1.16 line spacing ratio is used for the Helvetica font.
Copy link to clipboard
Copied
Nice one!
I was able to solve it by setting the focus to another field, and setting that field's On Focus event to return the focus to the original field right away. It works quite nicely! See attached.
Only issue I'm seeing is it doesn't make the field smaller when you back-space or delete the text you entered...
Copy link to clipboard
Copied
Nice one!
I was able to solve it by setting the focus to another field, and setting that field's On Focus event to return the focus to the original field right away. It works quite nicely! See attached.
Only issue I'm seeing is it doesn't make the field smaller when you back-space or delete the text you entered...
Copy link to clipboard
Copied
Great! That works fine, thanks.
I had a first thought about how to resize the field when you delete some texts, but so far I haven't found...
I will continue to look for.
@+
Copy link to clipboard
Copied
I believe it will require calculating the number of lines in the field, which is much more complicated, since the length of each character is different (unless it's a mono-spaced font)... but if you find a solution, please post it here!
Copy link to clipboard
Copied
I did a solution resizing the field from a button, but it only works with Acrobat Pro as you must add it temporary add a new page, so you must add an application script:
if (app.formsVersion>=8) {
ajoutPage=app.trustedFunction(function(cettePage,largeur,hauteur) {
app.beginPriv();
this.newPage(cettePage,largeur,hauteur);
app.endPriv();
});
suppressionPage=app.trustedFunction(function(cettePage) {
app.beginPriv();
this.deletePages(cettePage);
app.endPriv();
});
}
See the attached file (in French) and if it interests you, tomorrow I will translate the script in English...
For the fieldFull method, I will look for...
@+
Copy link to clipboard
Copied
Hi,
Here is a first working file I did rather quickly, but I am locked with few problems for a couple of days.
It seems that works pretty fine when modifications are done from the end of the text except when we add a new character just after the last one following the "fieldFull" flag.
Example in my attached file:
If I delete the "d" character
then I re-add it, the field becomes blank
while if you delete the "d" then the "l"
you can continue typing correctly
An other problem is when we add some charaters a the middle of the text field. At the next "fieldFull" flag the cursor comes back at the end of the text, so it's not possible to directly continue the typing...
If you have an idea!!!
Let me know if you think these are problems that can be solved...
I hope you will understand my logic!
Ps: You can take your time 😉 I will not able to take care of that for few days;
@+
Copy link to clipboard
Copied
I will test it a bit more thoroughly (also need to understand exactly what all the variables mean), but I think the resetForm command is not needed. I commented it out and it seems to still work quite well, and the text doesn't disappear as it did in your example.
Also, I've noticed that sometimes the value of one of the items in longueursLignes is zero (after adding text and then deleting it). In that case you should remove it entirely from the array, so it would delete that line and resize the field accordingly.
Copy link to clipboard
Copied
In a few words:
longueurLignes is a table incremented after each "fieldFull" state that indicated the number of characters from the begining of the text until the end of each line.
ligneNo is the number of lines. It could be longueurLignes.length that would avoid ligneNo++ and ligneNo--.
reduireHauteur is a flag (0 or 1) that allows reducing the height of the field.
Take your time...
@+
Copy link to clipboard
Copied
Hi try67,
As you suggested I did a test removing the resetForm command, but that didn't work very well when the user write too quickly.... so I kept it.
I solved the first problem by reducing the number indicated for each line by 1 character. Indeed, when the fieldFull state is at 1 the maxi number of characters is the number preceding this change of state. This works well, but in this same case I still have a loss of the first character if the user types too quickly...
For the problem of modification in the middle of the text, I am still looking for a good solution. I had the idea to change "doNotScroll" to false if (event.selStart<leTexte.length && event.selEnd<leTexte.length) but that doesn't work very well... If you have an idea!
Attached is my last example file.
Thanks & @+

