CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Size a region according to its content

by Jorge Sousa » 29 Jan 2014 18:10

About

What does it mean "var s = $("<span/>").html(content).appendTo("body");" ?


$("<span/>"), it's to create a span tag

.html(content) inserts the html content into the span

.appendTo("body") is to add the span to the body so that we can check the height

all of these are jquery library functions, documented worldwide.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Davide » 29 Jan 2014 18:58

Hello,
thank you to your explanation, it were the use of the <span> tag which confused me.
With the following changes to the javascript function I can get the right height of the label based on its width :
Code: Select all
      JS.Add('function labelContentHeight(content) {');
      JS.Add('  var s = $("<label style=''font-family: Verdana,Arial,sans-serif; font-size: 1.1em;white-space: -moz-pre-wrap !important;' +
      ' white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word; width:233px; display:block;''/>").html(content).appendTo("body");');
      JS.Add('  var h = s.height();');
      JS.Add('  s.remove();');
      JS.Add('  return h;');
      JS.Add('}');


The only thing It has to be considered is the font family and size which have to be the same as the ones used int the HTML editor.
In which way I can set-up the default font in the html editor ?

Thank you,
Davide
Davide
 
Posts: 150
Joined: 14 Oct 2013 11:33

by Davide » 09 May 2014 11:19

Hello,
using the script and code you suggest me I can get the height of the label in input way.
In my project I save the retrieved label height to show each reagion with the right height.
Due to differences in browsers and users set up it happened that the height saved was not the right height for all circumstances.

I made some tests using OnRender event but without success.
Is there a way to get the same height information but in output way as when I need to show each region ?
Something like a round-trip to the browser to use the javascript function and calc the height ?
Or a javascript function the change the size of the region on the browser ?
Is each region rendered as a div ?

Thank you,
Davide
Davide
 
Posts: 150
Joined: 14 Oct 2013 11:33

by Jorge Sousa » 09 May 2014 15:18

Hi Davide

Sorry, but i don't understand very well what you want. You can send us an email or join skype, and even speak your native language.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Davide » 09 May 2014 16:50

Hello,

attached there is a simple project.
If you run it and "Add" some text from the HTML editor you note that if the text is more then 3 lines the underlying regions overlap.
I would like to size the added region so it can be rendered without overlap the others.

I'm trying to realize an on-line survey tool where the users can enter their response and read them ordered by input time.
A user should be able to enter some text in a dialog and after I would like to show it in a sort of panel list where each panel has different height based on the entered text.

I hope to be clear.
If not we you can contact me by skype : soluzionipmi

Thank you,
Davide
You do not have the required permissions to view the files attached to this post.
Davide
 
Posts: 150
Joined: 14 Oct 2013 11:33

by Alexander Bulei » 09 May 2014 17:42

Hi Davide,

Attached your changed demo.
Check the comments in code.

Best Regards.
You do not have the required permissions to view the files attached to this post.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by Davide » 10 May 2014 08:44

Thank you for your suggestion.
It works in a similar way to your previous answer and it is useful to show the last inserted forum answer.
My question (sure I didn't explain well what I need) is about how to show regions related to the prevoiusly saved users answers.

Each time a user add an answer to the forum I save it in a database.
Next time the user enter the forum I need to show him all users anwsers in regions with height based on the html saved and permit him to add more answers.
For each of the previously inserted answers I need to show the html content and a "Reply" button so I need a region to group the each answer and its related button togheter.
What I need is a way to get the right html height (the witdh could be fixed) to show each saved answer region (html + button) with the right region height avoiding overlapping between them.

Attached there is a modified test application.
Take a look at my note(in formCreate event) which explain my problem about the height of regions height.

Thank you,
Davide
You do not have the required permissions to view the files attached to this post.
Davide
 
Posts: 150
Joined: 14 Oct 2013 11:33

by Alexander Bulei » 12 May 2014 16:12

Hi Davide,

It can be done with invisible label, but in your case, easier to add new field to TClientDataSet (like contentHTMLSize) and save there the real height.

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 04 Jul 2014 13:44

What would be the code for

BrowserScript:= Format('labelContentHeight(%s)',[AnswerHTMLEditor.JQHTMLEditorOptions.jsGetContent]);

if component is as LabelEx instead of a HTML Editor?

Eroc
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 19 guests

Contact Us.