cancel
Showing results for 
Search instead for 
Did you mean: 

How to get number of rows in text area when I paste something in SAPUI5?

former_member184238
Participant
0 Kudos

Hi,

       In my application I am using text area as columns in a table. In that I am getting data in the text area cells  from another page.

To count the number of rows entered in the text area I am using below code and placing this count value as dynamic in text area.

var count = 0;

                for(var i=0; i<dataName.length; i++){

                if(dataName[i] !== undefined){

                    if(count < dataName[i].split(/\r|\r\n|\n/).length){

                                count = dataName[i].split(/\r|\r\n|\n/).length;

                     }

                   }

                }

oTV = new sap.ui.commons.TextArea({

                      width : '100%',

                      rows : count,

                       value : dataName[int2-2],

                      editable : false,

                    });

Every thing is working fine when I press enter to go the next line.

But the problem is when I enter any data without using enter key or when I paste some data into that text area I am getting count value only one


I even used   count = dataName[i].split("\n").length; still I am getting count value "1". It's taking all the code entered in text area as one line.

How can we count the no of rows in text area without pressing enter key?

Pleased help me to solve this.

Thanks&Regards

Sridevi.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You can use jQuery to detect changes on the textarea, this includes typing, pasting,...

$('#textareaID').bind('input propertychange', function() {

 

for(var i=0; i<dataName.length; i++){

                if(dataName[i] !== undefined){

                    if(count < dataName[i].split(/\r|\r\n|\n/).length){

                                count = dataName[i].split(/\r|\r\n|\n/).length;

                     }

                   }

                }




});


replace textareaID with the id of the textarea.

former_member184238
Participant
0 Kudos

Hi,

Thanks for your reply.

This is the data coming from back end.we are not applying any events for that data and we are not applying enter key when enter data into that text area

But here when I am using   count = dataName[i].split(/\r|\r\n|\n/).length; I am getting count value 1.Because it takes all the data in one line.

Please suggest me.

Thanks&Regards

Sridevi

Former Member
0 Kudos

Hi,

Please try the code I sent you. It should detect any change to the textfield, also when you don't press the enter key.  It binds a listener to the textarea. Make sure that above listener is already binded to the textarea before the data is put in it.

I don't know exactly how your code is, but I think you need to do something like this:

var count = 0;

$(function() {       

        $('#textareaID')

             .bind('input propertychange', function() {

                for(var i=0; i<dataName.length; i++){

                    if(dataName[i] !== undefined){

                        if(count < dataName[i].split(/\r|\r\n|\n/).length){

                                count = dataName[i].split(/\r|\r\n|\n/).length;

                     }

                   }

                }

             });

});

All you should do is change textareaID with the ID of your textarea (or whatever selector you need). If you don't know jQuery, please do some research on jQuery selectors so you know what to put there.

Kind regards