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.

@+

bebarth
Community Expert
bebarthCommunity ExpertAuthor
Community Expert
March 2, 2024

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.


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 & @+