cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ginko
Helper III
Helper III

Can text box width respond to length of text?

As the title says, I am interested in making some of my text labels have responsive control width's depending on the length of text within them. I am using a function on the Fill property and it would look a lot better if the control it fills is only as long as the text of the selection made.

 

What would this width property function look like, is this even possible?

1 ACCEPTED SOLUTION

Accepted Solutions
TheRobRush
Super User
Super User

There's too many issues with what you changed to combine them honestly

For Example

In

If(Len(Self.Text)*100<100,100,Len(Self.Text)*12)

 

Len(Self.Text)*100 - With this, even ten characters in a text box is going to be checking against a value of 1000, thats a massive number to chekc against for a 10 character string, very inaccurate.

 

and in the second half

If(Len(Self.Text)*0<300 

 

Len(Self.Text)*0 will never have any other value than 0, so it will always come out as true, and therefore give you a width of 500 every single time.

 

Here you will see I shortened short side a little for you , and brought down full size a bit 

If(Len(Self.Text)*10<75,75,Len(Self.Text)*8.5)

 

and here are several examples from 5 digits up to 100 to show it looks good with just this

100 dig.PNGfifteen.PNGfive.PNGten.PNGthirty.PNGtwenty.PNG

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

6 REPLIES 6
TheRobRush
Super User
Super User

You would need to do something similar to this with a text box's width property

 

If(Len(Self.Text)<100,
   320,
   Len(Self.Text)<200,
   440,
   Len(Self.Text)<300,
   540,
   640)

 

 

Or even work out a mathematical formula based on len and how large you made your font for example

 

 

If(Len(Self.Text)*10<100,100,Len(Self.Text)*10)

 

 

Seems to work pretty well for Open Sans 13

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Hi Rob, this is really cool, I've been playing with it and this works really well for the long item names.

If(Len(Self.Text)*0<300,500,Len(Self.Text)*5)

 

However, when item names are shorter than these specs, the formula doesn't apply well and makes for a wide box. I've been trying to make an Or, ||, && addition to the function but I'm clearly doing it wrong because nothing beyond the original function has an effect.

 

Would you be able to help define what this function would look like if it took into consideration text that is both very long and shorter than the pre-defined measures? I hope that makes sense... 🙂

TheRobRush
Super User
Super User

What I originally wrote already does account for short text,

If(Len(Self.Text)*10<100,100,Len(Self.Text)*10)

First portion, If Len(Self.Text) < 100, means if this text formula is shorter then 100 give it a minimum width of 100, can change that 100 to whatever works for you. 

 

The way you have changed it to 

If(Len(Self.Text)*0<300

should always return to you a 500 width box since ANY number multiplied by 0 will always be less than 300.

 

 

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

@TheRobRush Okay to add onto my previous reply, I just found this works really well for the short text. How can I combine these two together to manage the min's and max's out there.

 

Short Text - 

If(Len(Self.Text)*100<100,100,Len(Self.Text)*12)

Long Text - 

If(Len(Self.Text)*0<300,500,Len(Self.Text)*5)
TheRobRush
Super User
Super User

There's too many issues with what you changed to combine them honestly

For Example

In

If(Len(Self.Text)*100<100,100,Len(Self.Text)*12)

 

Len(Self.Text)*100 - With this, even ten characters in a text box is going to be checking against a value of 1000, thats a massive number to chekc against for a 10 character string, very inaccurate.

 

and in the second half

If(Len(Self.Text)*0<300 

 

Len(Self.Text)*0 will never have any other value than 0, so it will always come out as true, and therefore give you a width of 500 every single time.

 

Here you will see I shortened short side a little for you , and brought down full size a bit 

If(Len(Self.Text)*10<75,75,Len(Self.Text)*8.5)

 

and here are several examples from 5 digits up to 100 to show it looks good with just this

100 dig.PNGfifteen.PNGfive.PNGten.PNGthirty.PNGtwenty.PNG

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Makes total sense, and I agree that does fit pretty darn well. I'm gonna use this but also just got this to work.

 

If(Len(Self.Text)>45, 500, (If(Len(Self.Text)*100<100,100,Len(Self.Text)*9)))

 

This is doing a good job first regulating my items that are super long, but then be kind to the shorter item names. Apologies if it sounds like I'm not listening (I am! haha) because I still have the *100 in there, but I think this meets the best of both worlds.

 

Thank you so much for these functions, this is such an awesome transferable function to understand!

 

Sean

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,408)