EasyUI Forum
July 17, 2018, 08:15:24 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Textbox - Multiline auto height  (Read 132 times)
jega
Jr. Member
**
Posts: 87


View Profile
« on: June 12, 2018, 01:25:28 AM »

Hi.

Have i missed something.

Having a multiline textbox, filled with text from db. Expected that the height is set, so i can see all the text, when height:'auto'

               <input id="dbhPurpose" name="dbhPurpose" class="easyui-textbox" data-options="
                     width:400,
                     height: 'auto',
                     multiline:true">

Jesper
Logged
jarry
Administrator
Hero Member
*****
Posts: 1406


View Profile Email
« Reply #1 on: June 12, 2018, 05:30:11 PM »

Please call the extended 'autoHeight' method.
Code:
(function($){
  function setHeight(target){
    var opts = $(target).textbox('options');
    $(target).next().css({
      height: '',
      minHeight: '',
      maxHeight: ''
    });
    var tb = $(target).textbox('textbox');
    tb.css({
      height: 'auto',
      minHeight: opts.minHeight,
      maxHeight: opts.maxHeight
    });
    tb.css('height', 'auto');
    var height = tb[0].scrollHeight;
    tb.css('height', height+'px');
  }

  function autoHeight(target){
    var opts = $(target).textbox('options');
    var onResize = opts.onResize;
    opts.onResize = function(width,height){
      onResize.call(this, width, height);
      setHeight(target);
    }
    var tb = $(target).textbox('textbox');
    tb.unbind('.tb').bind('keydown.tb keyup.tb', function(e){
      setHeight(target);
    });
    setHeight(target);
  }
  $.extend($.fn.textbox.methods, {
    autoHeight: function(jq){
      return jq.each(function(){
        autoHeight(this);
      })
    }
  })

})(jQuery);

Code:
$('#dbhPurpose').textbox('autoHeight');
Logged
jega
Jr. Member
**
Posts: 87


View Profile
« Reply #2 on: June 13, 2018, 09:57:58 AM »

Thanks for reply jarry

Works fine as a method.

What if i want it as a property, with true/false, and default false. How could that be done?. Know how to make an extended method, but how to make an property

Jesper
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!