最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - controlling the size of textarea with jeditable - Stack Overflow

programmeradmin1浏览0评论

My objective: Allowing inline-edition of a description with the jquery plugin jeditable.

My problem: The textarea input is bigger than the original div, leading to the apparition of scroll-bars.

Attempted solution:

$('.editableDescription').editable('/', {

id: 'data[Chantier][id]',
name: 'data[Chantier][Description]',
type: 'textarea',
height: $(".editableDescription").height() + "px",
width:  $(".editableDescription").width()+ "px",
onblur: 'submit',
tooltip: ''

});​

I tried to take the size of the wrapper div with jquery, but it still fails!

jsFiddle:jsFiddle

My objective: Allowing inline-edition of a description with the jquery plugin jeditable.

My problem: The textarea input is bigger than the original div, leading to the apparition of scroll-bars.

Attempted solution:

$('.editableDescription').editable('http://jsfiddle/echo/jsonp/', {

id: 'data[Chantier][id]',
name: 'data[Chantier][Description]',
type: 'textarea',
height: $(".editableDescription").height() + "px",
width:  $(".editableDescription").width()+ "px",
onblur: 'submit',
tooltip: ''

});​

I tried to take the size of the wrapper div with jquery, but it still fails!

jsFiddle:jsFiddle

Share Improve this question asked Aug 14, 2012 at 8:18 L. SannaL. Sanna 6,5627 gold badges35 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

First, you need to remove height:250px; from .longtext, or else Jeditable will take it as the default height for the <textarea>.

Then I made sure that .longtext had the same styles as the <textarea> that will be nested inside it, such as line-height, font-size, font-family.

And I assumed that you'll probably have more than one .longtext in your document, so you will need to apply different heights to different <textarea>s. So I changed this:

$('.editableDescription').editable('http://jsfiddle/echo/jsonp/',
{
        id        : 'data[Chantier][id]',
        name      : 'data[Chantier][Description]',
        type      : 'textarea',
        height:($(".editableDescription").height()) + "px",
        width: ($(".editableDescription").width()) + "px",
        onblur: 'submit',
        tooltip   : ''
});

​ to this:

$('.editableDescription').each(function()
{
    $(this).editable('http://jsfiddle/echo/jsonp/',
    {
        id:'data[Chantier][id]',
        name:'data[Chantier][Description]',
        type:'textarea',

        height:$(this).height()+'px',
        /* here it will take the height of the currently active .longtext */

        width:$(this).width()+'px',
        onblur:'submit',
        tooltip: ''
   });
});

DEMO

And that's basically it.

You may try to set the CSS overflow property to hidden

发布评论

评论列表(0)

  1. 暂无评论