How to add a new line in Yii2 Data Confirm

1k Views Asked by At

I have a button using the following code in my view...

<?= Html::submitButton('Delete Summary', [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Really long message.<new line>Line 2<new line>Line 3?',
                'method' => 'post',
            ],
        ]) ?>

I want to make the eventual confirmation dialog show my text on different lines, but none of the common notations such as \n, <br>, nor &#10;&#13; work. I also tried putting \\n instead of \n, still it did not work.

How can I make the different parts of my confirmation show on a different line.

2

There are 2 best solutions below

0
On BEST ANSWER

Just write as with the newline

<?= Html::submitButton('Delete Summary', [
        'class' => 'btn btn-danger',
        'data' => [
            'confirm' => 'Really long message.
            Line 2
            Line 3?',
            'method' => 'post',
        ],
    ]) ;
  ?>
0
On

You can use \n is you define string using " quotes:

<?= Html::submitButton('Delete Summary', [
    'class' => 'btn btn-danger',
    'data' => [
        'confirm' => "Really long message.\nLine 2\nLine 3?",
        'method' => 'post',
    ],
]) ?>

You can also split it into multiple lines to improve readability:

<?= Html::submitButton('Delete Summary', [
    'class' => 'btn btn-danger',
    'data' => [
        'confirm' => "Really long message."
            . "\nLine 2"
            . "\nLine 3?",
        'method' => 'post',
    ],
]) ?>