Skip to main content
bebarth
Community Expert
Community Expert
February 23, 2024
Answered

Resize automatically the height of a field according to the number of lines

  • February 23, 2024
  • 1 reply
  • 6371 views

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.

This topic has been closed for replies.
Correct answer try67

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...

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 23, 2024

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...

bebarth
Community Expert
bebarthCommunity ExpertAuthor
Community Expert
February 23, 2024

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.

@+

try67
Community Expert
Community Expert
February 23, 2024

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!