You are viewing limited content. For full access, please sign in.

Question

Question

Is it possible to set readonly property to multiline field which has unpredictable line?

asked on November 9, 2014

Hello everyone,

Some fields in my client forms are multi line which has unpredictable data line.

I try to set field to be readonly field.

such as:

$(document).ready(function(){
     
   $('.Multi textarea').text('1 test1'+'\n'+'2 test2'+'\n'+'3 test3'+'\n'+'4 test4');
   $('.Multi textarea').attr('readonly', 'readonly'); 
  
});

I set  4 lines sample data to this field  as you can see.

But I found that data was show only 3 lines because of setting height field to 3 lines.

(Actually I don't know how many data should be fill in this field.)

So How could we set a multi-line field to be readonly and show all unpredictable data in that field?

Thank you for any help.

 

Multiline_field_set_line.png
Multiline_readonly_Issue.png
0 0

Answer

SELECTED ANSWER
replied on November 9, 2014 Show version history

You can add following code below your original code to archive this:

    $('textarea[readonly]').each(function () {
        if (this.scrollHeight != $(this).height())
            $(this).height(this.scrollHeight);
    })

 

1 0

Replies

replied on November 9, 2014

Hi Xiuhong Xiang,

     It works perfectly! Thank you very much for your professional support.

Best regards,

Bongkoch.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.