Shahid Thaika
Shahid Thaika

Reputation: 2305

How to add a new line in Yii2 Data Confirm

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.

Upvotes: 1

Views: 1130

Answers (2)

rob006
rob006

Reputation: 22154

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',
    ],
]) ?>

Upvotes: 1

ScaisEdge
ScaisEdge

Reputation: 133360

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',
        ],
    ]) ;
  ?>

Upvotes: 0

Related Questions