set maximum number of line in text box

set maximum number of line in text box

  

 Hi Expert,

I have set a number of text lines in a texbox, but still i can exceed the number of text lines that i have given.

Is it possible to set a maximum number of line and a number text per line.

Example:

line 1 : must not exceed in 35 txt

line 2: must not exceed in 35 txt

with a  total of Max.lenght of 70



Hope you can help with this.

Thank in advance.

That's not native. If your scenario is that specific, you can do it in javascript. Looking for a generic solution you can have one condition easily, not both.

Here's a fiddle with a line limiter: http://jsfiddle.net/XNCkH/17/



Nuno Reis wrote:

Hi Nuno,


Thanks for the prompt reply.

After reading your reply.

I search on the net and found out that there are people with this same problem.

and found a solution. 

my next question is how can i insert this code on the outsystems.

Can someone give me a step by step solution.

Sorry i'm a newbie on using the outsystems.


Thank you for your patient with me.


<textarea id="foo" cols="20" var rows="3"></textarea>

$(document).ready(function(){
    var textArea = $('#foo');
    var maxRows = textArea.attr('rows');
    var maxChars = textArea.attr('cols');
    textArea.keypress(function(e){
        var text = textArea.val();
        var lines = text.split('\n');
        if (e.keyCode == 13){
            return lines.length < maxRows;
        }
        else{ //Should check for backspace/del/etc.
            var caret = textArea.get(0).selectionStart;
            console.log(caret);
           
            var line = 0;
            var charCount = 0;
            $.each(lines, function(i,e){
                charCount += e.length;
                if (caret <= charCount){
                    line = i;
                    return false;
                }
                //\n count for 1 char;
                charCount += 1;
            });
                   
            var theLine = lines[line];
            return theLine.length < maxChars;
        }
    });
   
});




That's not native. If your scenario is that specific, you can do it in javascript. Looking for a generic solution you can have one condition easily, not both.

Here's a fiddle with a line limiter: http://jsfiddle.net/XNCkH/17/





Solution

Select the page/web block where you have the textarea and in Advanced will find a Javascript section.

There you can add anything.


Solution

Thanks a lot.


Nuno Reis wrote:

Select the page/web block where you have the textarea and in Advanced will find a Javascript section.

There you can add anything.