1. #1
    Sencha User
    Join Date
    May 2013
    Posts
    7
    Vote Rating
    0
    kushal.bagaria is on a distinguished road

      0  

    Default Unanswered: wrap off for textarea

    Unanswered: wrap off for textarea


    Textarea is wrapping off the line which I don't want. Instead I want a horizontal scroll bar I line exceeds textarea's width. I tried textarea.getElement().setAttribute("wrap","off") but its not working. Same is working for gwt's textarea.

    Please suggest some solution.

  2. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    You're very close. The problem is when you call getElement, you're actually retrieving the <div> two ancestors up from the actual <textarea> element which is why it's not working.

    You need to get a handle to the actual "input" element and there are two ways to do this:

    Code:
    // sub class the object
    public class MyTextArea extends TextArea
    {
      public MyTextArea()
      {
        XElement elt = this.getInputEl();
        elt.setAttribute("wrap", "off");
      }
    }
    or,

    Code:
    // modify the text area's cell
    TextArea ta = new TextArea();
    TextAreaInputCell cell = (TextAreaInputCell) ta.getCell();
    cell.getInputElement(ta.getElement()).setAttribute("wrap", "off");
    Both work and both are fine to use. If this is a one-off, I'd go with the latter. If you have the need to do this in more than one place, create a reusable widget and call it, say, NonWrappingTextArea.

Thread Participants: 1