Textarea auto height based on contents

  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1

baileynp created the topic: Textarea auto height based on contents

Hi all

I'm putting together another form which is a questionnaire, and currently looks like:



As you can see, it consists of individual checkboxes (not a group), and text areas. The fields are populated via an SQL query at runtime.

My question is how to set the textareas' height based on the content, which as you can see is variable length.

Is there any way to do this?

Or, if not, can you suggest another way of displaying this text to the right of the checkboxes?

As ever, your humble and obedient servant. :)
#237427
Attachments:
  • Posts: 5896
  • Karma: 118
  • Thank you received: 544

MarioPuco replied the topic: Textarea auto height based on contents

Hi,

We don't have this feature I'm sorry :(
But I just googled around and it feels really easy to setup, so here are the steps I did :

1) example : jsfiddle.net/C8e4w/1/
2) Set your textarea height to 0 ( inside element option )
3) Go to your Initialization Script and add this code inside the function :
jQuery('#ff_elem10915').wrap('<div id="content"> </div>');

jQuery('#content').on( 'change keyup keydown paste cut', 'textarea', function (){
    jQuery(this).height(0).height(this.scrollHeight);
}).find( 'textarea' ).change();

As the example shows you need a DIV around your textarea elements so that's why I used jQuery('#ff_elem10915').wrap('<div id="content"> </div>'); and you will need to use it for all your textarea elements.

Here is a working link : mrpuco.com/index.php/radiogroup

Regards,
Mario

Satisfied with our Support ?
PayPal Tip
===============================================
Need to renew Pro Support?
Buy Here!
===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
#237430
  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1

baileynp replied the topic: Textarea auto height based on contents

Hi - thanks for the quick response. :)

Well, it sort of works. ;)

I set the textareas' heights to 0px in form design.

I added the following code to the script that is run when a 'next' button is clicked:
// Set textarea contents
ff_getElementByName('txt_' + section + '_' + arr[i][2]).value = arr[i][4];

// Set textarea height
var txt_area_id = ff_getElementByName('txt_' + section + '_' + arr[i][2]).getAttribute("id");
jQuery('#' + txt_area_id).wrap("<div id='content'> </div>");
jQuery('#content').on( 'change keyup keydown paste cut', 'textarea', function () {
		jQuery(this).height(0).height(this.scrollHeight);
}).find( 'textarea' ).change();

... and I get this. :)



The <div> is being correctly inserted, and I've tried moving the line
// Set textarea contents
ff_getElementByName('txt_' + section + '_' + arr[i][2]).value = arr[i][4];
to after the set height part, but with the same result.

Help :)
#237433
Attachments:
Moderators: ForumSupporttomeperica
Time to create page: 0.200 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here