5 Replies Latest reply: Aug 19, 2012 6:59 AM by Timo Hahn RSS

    How to freeze the number of rows in af:inputtext

    845678
      Hi all - i have requirement like user should enter only 13 lines after that application should not allow the any characters.
      am using af:inputtext 13 rows by default it is showing 13 rows , if user trying to enter more than 13 lines it was allowing. is there any specific configuration to restrict rows.

      i tried with h:textbox even that had same problem. through scrip we restricted to 13 lines for based on each enter in the box.
      but if user copied 5 lines and if he press enter it was considering 5 lines as single row .

      Could you please suggest me the what best way.


      thanks.

      Edited by: 842675 on Aug 18, 2012 6:12 AM
        • 1. Re: How to freeze the number of rows in af:inputtext
          vinod_t_krishnan
          there is a maximumLength proeprty in inputText which u can use
          • 2. Re: How to freeze the number of rows in af:inputtext
            845678
            Hi Vindod - thanks for your reply.

            if users enters one character in first line same way in remaining lines also enters single characters. it will allow more than 13 rows.

            that's not suits to our requirement.

            in the 13 lines each row we will store in different table. individual text we should not use.


            Thanks.
            • 3. Re: How to freeze the number of rows in af:inputtext
              vinod_t_krishnan
              you can restrict that using the javascript. new line is counted as 2 characters. you will have to play with the maximum length accordingly..
              • 4. Re: How to freeze the number of rows in af:inputtext
                845678
                Thanks again Vinod.

                am sorry i didn't get what your suggesting. Could you pleas help me any code snippet.

                Thanks
                • 5. Re: How to freeze the number of rows in af:inputtext
                  Timo Hahn
                  The af:inputText allows a number of characters in the whole component. It doesn't matter of you enter a character or a new line. It just counts the number of characters. This is controlled by the maximumLength property of the component.
                  The rows property just shows the component on the page with enough height to show the given number of text.
                  As your requirement is to controll the number of lines (rows) entered into the component, you have to use some other kind of control mechanism. Depending on the use case this can be done using JavaScript or e.g. by using a converter or client side validator.
                  Converter and validator are only checked when you leave the field, so the user might enter more then 13 lines and when he leave the field he gets an error message. Using JavaScript you can write a client method which counts the number of new line caracters and whenever you count 13 you just cancel the key event and no more characters are allowed. I would implement it in a way that you cancel the 13th new line character event. Then you can still edit all other lines and can type in more characters until you reach the maximumLength.

                  Timo