How to set max of text that will be showed?

How to set max of text that will be showed?

  

i want to show the text but with limit, like 30 character. And i already add this script but didn't affect anything. And for the expression that i want to add this script there is a render action to disappear html tag, so any one know to solve this? 

Hi Erron,

 Can you please share your OML file so i can identify the issue. because the approach you are follow is right approach.   

this is my oml

chandra vikas sharma 

I've already shared 

Hello Erron, 

It looks like you are using an expression to show the text, and you want to limit the text to 30 characters, right?

You can do this with the Substr builtin function from the Text built in functions:

Hope this helps.
Cheers.

EDIT, disregard this, as I didn't notice that you wanted to add ellipses.

Eduardo Jauch

I've been add this on my script, at that picture above

Hi,

 For my current project, I am using the same and it's working for me

SyntaxEditor Code Snippet

M not able to see any difference

If(Length(PredictionsTournaments.List.Current.Tournament.TourName)>20,Substr(PredictionsTournaments.List.Current.Tournament.TourName,0,20)+"..",PredictionsTournaments.List.Current.Tournament.TourName)

For escaping HTML content i am setting it to yes

Regards,

Pankaj

Y

ou don't need all that "script" (it is not really a script).

You just need the Substr. If there are more characters, they will be cut. If there are less characters, they will be shown entirely.

No need to an IF (that is probably what is messing with the text)

EDIT, disregard this, as I didn't notice that you wanted to add ellipses.

Pankaj pant 

I build this in mobile application so there is no escape html content



P.S. If you want to use ellipses, than you can add them through CSS instead of using this code.

https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/

Cheers

Hi Erron,

Can you please explain what you mean by it not "affecting anything"? Your code looks like it should work. Did you try to debug it?

That said, you should probably solve this with the CSS text-overflow property. See here for details. [EDIT: Eduardo ninja'd me :)]

Eduardo Jauch wrote:

You don't need all that "script" (it is not really a script).

You just need the Substr. If there are more characters, they will be cut. If there are less characters, they will be shown entirely.

No need to an IF (that is probably what is messing with the text)


Still the same

Eduardo Jauch

Eduardo Jauch wrote:

You don't need all that "script" (it is not really a script).

You just need the Substr. If there are more characters, they will be cut. If there are less characters, they will be shown entirely.

No need to an IF (that is probably what is messing with the text)

Not sure if I follow here Eduardo. They need to add the ellipsis at the end, so there's a need to check whether the original text was cut-off. Of course, it's possible to always do a SubStr, then use the if to check whether the ellipsis is needed, but I don't see any advantage in that. Also, what kind if "messing with the text" do you have in mind?


Well,

I am seeing 6 letters...What do you expect to happen if the limit you're setting is 30 or 50 characters?

The Sbstr will not cut anything if the text is smaller than the limit.
Even your IF will not cut, as like the lenght of the text is smaller than the limit, it will show the entire text...

To your IF or the ellipses with CSS to work, the text must be grater than the limit of characters or the size of the parent.

EDIT
The Lenght function will test against the ACTUAL number of characters present in the attribute, not the size of the attribute... Is this the confusion?

Kilian Hekhuis wrote:

Eduardo Jauch wrote:

You don't need all that "script" (it is not really a script).

You just need the Substr. If there are more characters, they will be cut. If there are less characters, they will be shown entirely.

No need to an IF (that is probably what is messing with the text)

Not sure if I follow here Eduardo. They need to add the ellipsis at the end, so there's a need to check whether the original text was cut-off. Of course, it's possible to always do a SubStr, then use the if to check whether the ellipsis is needed, but I don't see any advantage in that. Also, what kind if "messing with the text" do you have in mind?


In the first answer I didn't noticed that the OP was adding the ellipses (i misread the expression).
The "messing" was that I was starting to think the OP was confusing the lenght of the actual characters in the attribute with the available size of the attribute. :)


Erron,

Why are you using a JavaScript to add a piece of HTML in the OnRender???
You don't need to do that. Just use the expression, no need to replace the innerHTML of the element...

Without the JavaScript code in the OnRender, the code works as expected (ass the innerHTML will not be replaced by the full text again).

Cheers.

EDIT.

Using your code with a fixed string (just for test) and removing the JavaScript:

Kilian Hekhuis wrote:

Eduardo Jauch wrote:

You don't need all that "script" (it is not really a script).

You just need the Substr. If there are more characters, they will be cut. If there are less characters, they will be shown entirely.

No need to an IF (that is probably what is messing with the text)

Not sure if I follow here Eduardo. They need to add the ellipsis at the end, so there's a need to check whether the original text was cut-off. Of course, it's possible to always do a SubStr, then use the if to check whether the ellipsis is needed, but I don't see any advantage in that. Also, what kind if "messing with the text" do you have in mind?


my text has a render action which is the action use for eliminate the HTML tag. And because the text was a description text and it's so long i want to add limit to this text. Then i add the script above but didn't affect after all.


Eduardo Jauch wrote:

Hello Erron, 

It looks like you are using an expression to show the text, and you want to limit the text to 30 characters, right?


You can do this with the Substr builtin function from the Text built in functions:

Hope this helps.
Cheers.


EDIT, disregard this, as I didn't notice that you wanted to add ellipses.

it's just the example, the real text actually is long, and for the example "yeyeye" i add limit only 0-3 character 


Hello Erron,

Without the JavaScript, your code should work. I just removed that code and replaced the fetch inside the data action by a fixed string to test (as I don't have your data), and it works.

Please, test it without this JavaScript in the OnRender.

Eduardo Jauch wrote:

Erron,

Why are you using a JavaScript to add a piece of HTML in the OnRender???
You don't need to do that. Just use the expression, no need to replace the innerHTML of the element...

Without the JavaScript code in the OnRender, the code works as expected (ass the innerHTML will not be replaced by the full text again).

Cheers.

EDIT.

Using your code with a fixed string (just for test) and removing the JavaScript:


I know it will work well without the Javascript, but i want to remove the html tag, and also i want to add limit for the text. 

Erron,

Which HTML TAG are you trying to remove? And why?

In any case, whatever you're doing, probably, if you replace the text by the cropped version of it in the result INSIDE the Data Action, it should also work (but them you will have only the cropped version).

EDIT:

Just to explain what is happening, the JavaScript you're running will use the original text, and replace the cropped version when it runs, as the expression is being evaluated before it. 

Eduardo Jauch wrote:

Erron,

Which HTML TAG are you trying to remove? And why?

this is the real text, and the user want to me to remove the tag, and add limit only one sentence  

Erron,

Your scenario seems to be much more complex than what seemed at first. :)

You want to remove HTML TAGS from a TEXT. You need to do this before you crop the text, and the way is not through JavaScript.

There is a SERVER SIDE extension that can do it:

https://www.outsystems.com/forge/component/145/html-utils/?Unfollow=False

It allows you to get an HTML and remove the TAGS, returning only the text.
But you need to hit the server to be able to use it.

I'm not alware of any plugin for mobile (you may search the Forge) already ready to do this...

The problem to to this with JavaScript, is that you have MANY tags in the text, not only one. And you would have to drop the text also in the JavaScript (to avoid losing the crop).

EDIT: If your application is not meant to work OFFLINE, it's ok to use the extension.
If your app is meant to work OFFLINE, you will need to store the text locally (local storage), and this allows you to do this operation, stripping the HTML, server side, using the extension. In any scenarion, I think the way to go to do what you want is through this extension, and avoiding use the JavaScript.

On the other hand, if you are SURE that the text will be inside paragraphs (<p>), you can find the first and second and take this text and use it. If the requirement is not to limit the number of characters, but to the first sentence, I would check this possibility (that would not require the extension).

Eduardo Jauch 


Okay i'll try all of your suggestion thank you very much.