2

I'm wondering about that the default textarea of Yii2 does not show newlines per default. And the Yii2 model does not save the newlines into the DB.

I didn't found anything in the Yii2 documentation, so hopefully you guys can help me - this is more than weird for me :-(

pixel-shock
  • 67
  • 1
  • 9

2 Answers2

5

You could use the ntext format in widgets such as ListView, GridView:

'format' => 'ntext',

ntext: the value is formatted as an HTML-encoded plain text with newlines converted into line breaks.

robsch
  • 9,358
  • 9
  • 63
  • 104
drodata
  • 517
  • 3
  • 11
  • Hi, sorry - I forgott to explain my context: I'm in an "edit-view" and I'm using an activeField like this: `
    = $form->field($studio, 'studioDescription')->textArea()->label( PhobUtils::t('Description') ) ?>
    `
    – pixel-shock Feb 21 '16 at 09:23
0

Introduce "word-wrap" as in any normal html. In your case.

<?= $form->field($studio, 'studioDescription')->textArea(array('rows'=>25, 'style' => 'resize:none; word-wrap:break-word;'))->label( PhobUtils::t('Description') ) ?>
Sunil Lama
  • 4,531
  • 1
  • 18
  • 46
  • Hi, I don't think that's an CSS Problem ... My Problem is, that the \n and \r values are not shown as newlines in the Textarea. If I'm pasting the text from the DB into the textarea the textarea shows the newlines correctly, but not when Yii2 put's the content into the textarea – pixel-shock Feb 21 '16 at 09:36