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
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.
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',
],
]) ;
?>
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',
],
]) ?>
Related
How to set my template and labelOptions in Select2 in Yii2? For a regular field, this can be done via field->labelOptions and field->template. And how to do it for Select2?
$form->field($model, 'test',[
'labelOptions' => ['style' => 'display:none !important;'],
'template' => '{label}{input}{error}'])
->radioButtonGroup($data, ['itemOptions' => ['class' => 'btn btn-default', 'style' => 'display:none !important;']
]); ?>
Select2, which is in question: https://demos.krajee.com/widget-details/select2
I asked the question himself and answered it himself, and even in the question itself. It was enough to do as in the example from the question - set field->template and field->label Options as needed:
$form->field($model, 'test', [
'template' => '{label}{input}{error}'
])->widget(Select2::classname(), [
'data' => $data,
'pluginOptions' => [
'allowClear' => true
],
]);
I have a following code below:
<?= $form->field($model, 'date') ->widget(yii\jui\DatePicker::className(),['clientOptions' => [ 'placeholder' => 'dd/mm/yyyy',
'id' => 'form',
'autocomplete' => 'off',
'value' => date('m/d/Y'),
'autoclose'=>true,
]]) ?>
That will result in HTML in following way:
<div class="form-group has-icon has-label">
<label for="formSearchUpLocation">Picking Up Location</label>
<input type="text" class="form-control" id="formSearchUpLocation" placeholder="Airport or Anywhere">
<span class="form-control-icon"><i class="fa fa-map-marker"></i></span>
</div>
My question is as following:
How can I integrate the css and bootstrap classes in HTML below into yii2 active form above?
Thank you for your help.
if you are looking to add the class to all the group divs mean all the div that have the class form-group then you can use the fieldConfig option of the ActiveForm or if you want it for one specific field then you can use the options option of the $form->field() as the 3rd parameter
For the whole Form
$form = yii\widgets\ActiveForm::begin([
'fieldConfig' => [
'options' => [
'class' => 'my-group'
]
]
]);
For Single Field
echo $form->field($model, 'name', ['options' => ['class' => 'my-class']])->textInput();
Conversion
About converting your above HTML using ActiveForm the following should work you can use template option of the $form->field() 3rd parameter to add your custom icon after the input, along with other, see below will create your desired HTML
echo $form->field($model, 'date', [
'options' => [
'class' => 'form-group has-icon has-label'
],
'inputOptions' => [
'class' => 'form-control'
],
'template' => '{label}{input}<span class="form-control-icon"><i class="fa fa-map-marker"></i></span>{error}'
])->widget(yii\jui\DatePicker::class, [
'id' => 'created_at',
'options' => [
'placeholder' => 'Airport or Anywhere'
]
]);
You will have something like below
<?= $form->field($model, 'date') ->widget(yii\jui\DatePicker::className(),['clientOptions' => [ 'placeholder' => 'dd/mm/yyyy',
'id' => 'form',
'class' => 'WRITE-YOUR-CLASS'
'autocomplete' => 'off',
'value' => date('m/d/Y'),
'autoclose'=>true,
]]) ?>
just input your class name in 'class' section it will work.
example : 'class' => 'fa fa-map-marker'
You could try something like the code bellow to concat your calendar icon with the widget:
<?php
$addon = '<span class="input-group-addon">
<i class="fa fa-calendar-alt"></i>
</span>';
echo $addon.$form->field($model, 'date')->widget(yii\jui\DatePicker::className(),['clientOptions' => [ 'placeholder' => 'dd/mm/yyyy',
'id' => 'form',
'autocomplete' => 'off',
'value' => date('m/d/Y'),
'autoclose'=>true,
]]);
?>
Or you can try search more on the plugin you are using, some widgets have his own attribute to render the calendar icon.
I have a custom action column with just the delete button:
[
'class' => 'yii\grid\ActionColumn',
'template' => '{delete}',
'buttons' => [
'delete' => function($url, $data){
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['orders-lines/delete', 'id' => $data->id], [
'data' => [
'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]);
}
]
],
and whenever i click the trash icon, then accept the alert box, the same alert box is triggered again so I have to accept twice the alert box.
What could i be missing?
Thanks
Try this
['class' => 'yii\grid\ActionColumn',
'template' => '{delete}',
'buttons' => [
'delete' => function ($url, $data) {
return Html::a('<span class="glyphicon glyphicon-trash" title="Delete"></span>', ['orders-lines/delete', 'id' => $data->id], ["data-pjax" => 0, 'onClick' => 'return confirm("Are you sure you want to delete this item?") ']);
},
],
],
I'm trying to send parameteres via yii\bootstrap\Html;
echo Html::a('Создать', ['/orders/order-create','freelancer_group'=>$_GET['freelancer_group']], ['class'=>'btn btn-lg btn-primary','data'=>['method' => 'post','derp'=>'herp'],]);
But when I click on it is still var_dump($_POST['derp']); is NULL. How can I post it? I 've found it here
echo Html::a('Создать',
['/orders/order-create', 'freelancer_group' => $_GET['freelancer_group']],
[
'class' => 'btn btn-lg btn-primary',
'data' => [
'method' => 'post',
'params' => ['derp' => 'herp'], // <- extra level
],
]
);
I tried to add extra action buttons. Admin only view this button after button click update in a single field in the database.
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->can('admin')){
}
?>
</p>
My problem is that I have 3 users that are: applicant, faculty and admin (or hod). In this case after faculty recommendation, the admin (or hod) sanctioned the leave.
I create leave application and faculty recommended, so now I want get the recommended data when admin login to the site.
If admin is the username you should follow this way :
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id],
['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->identity->username == 'admin' ){
echo Html::a('Your Button Label for Admin',
['yourActionForAdmin', 'id' => $model->id],
['class' => 'btn btn-primary']);
}
?>
</p>