Search code examples
extjstextline-breaksword-wrap

How to make a word wrap in the text of an element (Text, Label, displayField) with ExtJS 4.2.1?


Must show a text that is greater than the component in which it is inserted. Currently, the text does not wrap automatically.

enter image description here

I've tried using the following components: Text, Label and Display Field


Solution

  • Have you tried a text that contains white space? A single word that is too long won't be wrapped ever, but multiple shorter, space-delimited words maybe will, depending on the component you use.

    If you want to show a long text, use a container and put the text into the html configuration, and it will auto-wrap.

    The components you named also have their usage, but not for simple long text:

    • text is from the draw package, and good for specialized formatting.
    • displayfield is good inside a form whenever you want to display (read-only) some value that is part of the record that you load into the form. displayfield won't wrap at all - try textareafield with readonly configuration for that.
    • label is good as the label of a form field, but only if used via the labelable mixin, which does most of the work. A label should make its content wrap around if you provide a fixed width or maxWidth, but it does not automatically adhere to the parent object layout.