I'm using Yii2-export plugin. By default, the button has a class btn btn-secondary btn-default and I want to add my classes to the button. I do it as follows:
<?= ExportMenu::widget([
'dataProvider' => $dataProvider,
'dropdownOptions' => [
'label' => 'Export',
'class' => 'btn btn-primary btn-sm font-weight-bold',
'icon' => '<i class="fas fa-external-link-alt icon-nm"></i>'
],
'columnSelectorOptions' => [
'icon' => '<i class="fas fa-list icon-nm"></i>',
'class' => 'btn btn-primary btn-sm font-weight-bold',
],
'exportConfig' => ...
'columns' => ...
]); ?>
But as a result, this is rendered:
<button id="w4-button" class="btn btn-primary btn-sm font-weight-bold btn-outline-secondary dropdown-toggle" title="Export data in selected format" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-external-link-alt icon-nm"></i> Эскпортировать</button>
That is, my classes are just written at the beginning and not applied. What should I do?
Related
I currently have a menu widget having following items this is item#1
$menuIteams[] = [
'label' => 'Vouchers',
'url' => '#',
'template' => '<a href="{url}" class="nav-link"><i class="icon-cash3"></i> <span>
{label}
<span class="d-block font-weight-normal opacity-50"></span> </a>',
'items' => [
['label' => 'View All', 'url' => ['/voucher/index'], 'template' => '<i class="icon-copy3"></i> {label}<span> '],
['label' => 'Create New', 'url' => ['/voucher/create'], 'template' => '<i class="icon-pen6"></i> {label}<span> '],
],
'options' => [
'class' => 'nav-item nav-item-submenu',
'data-submenu-title' => 'Layouts',
],
];
and am appending all items to menu widget
echo \yii\widgets\Menu::widget([
'options' => [
'class' => 'nav nav-sidebar',
'data-nav-type' => 'accordion',
],
'items' => $menuIteams,
'itemOptions' => array('class' => 'nav-item'),
'submenuTemplate' => "\n<ul class='nav nav-group-sub'>\n{items}\n</ul>\n",
'encodeLabels' => false, //allows you to use html in labels
'activateParents' => false,
]);
I want to my menuIteams[] {label} to appear on top of each respective sub menu item
So for above example Vouchers would appear on top of sub menu followed by list of items
Explained better with images
this to be similar to this
Of course the sidebar should be collapsed and sub menu should appear as a dropdown similar to be image#1
Html Rendered
<li class="nav-item nav-item-submenu" data-submenu-title="Layouts"><a href="#" class="nav-link"><i class="fas fa-print"></i> <span>
Print Digital
<span class="d-block font-weight-normal opacity-50"></span> </a>
<ul class='nav nav-group-sub' data-submenu-title=<li class="nav-item"><i class="icon-copy3"></i> Extra Material<span> </li>
<li class="nav-item"><i class="icon-copy3"></i> Finishing<span> </li>>
<li class="nav-item"><i class="icon-copy3"></i> Extra Material<span> </li>
<li class="nav-item"><i class="icon-copy3"></i> Finishing<span> </li>
</ul>
</li>
Expected
<li class="nav-item nav-item-submenu nav-item-open">
<i class="icon-color-sampler"></i> <span>Themes</span>
<ul class="nav nav-group-sub" data-submenu-title="Themes" style="display: block;">
<li class="nav-item">Default</li>
<li class="nav-item">Material</li>
<li class="nav-item">Dark</li>
<li class="nav-item">Clean <span class="badge bg-transparent align-self-center ml-auto">Coming soon</span></li>
</ul>
</li>
Figured it out from How to fetch data from database and set as submenus in yii2?
Had to move submenu template from menu widget to $menuIteams[]
$menuIteams[] = [
'label' => 'Cash Requisition',
'submenuTemplate' => "\n<ul class='nav nav-group-sub' data-submenu-title='Cash Requisition'>\n{items}\n</ul>\n",
'url' => '#',
'template' => '<a href="{url}" class="nav-link"><i class="icon-cash3"></i> <span>
{label}
<span class="d-block font-weight-normal opacity-50"></span> </a>',
'items' => [
['label' => 'View All Cash Requisitions', 'url' => ['/voucher/index'], 'template' => '<i class="icon-copy3"></i> {label}<span> '],
['label' => 'Create New Cash Requisition', 'url' => ['/voucher/create'], 'template' => '<i class="icon-pen6"></i> {label}<span> '],
],
'options' => [
'class' => 'nav-item nav-item-submenu',
],
];
I'm using some plugins (yii\widgets\MaskedInput)in dynamic-form, I notice that plugin work only at first element, when adding an option but this normal load but the entry "score" does not validate the entry of only numbers but allows you to enter text as a normal entry. Please advice. Thanks before.
My code like this.
_Form
<?php
$form = ActiveForm::begin([
'id' => 'dynamic-form',
"enableAjaxValidation" => true,
]);
?>
<div class="row">
<div class="col-sm-6">
<?=$form->field($model, 'title')->textInput(['maxlength' => true])->input('title', ['placeholder' => "Title Evaluation"]) ?>
<div class="row">
<div class="col-sm-6">
<?=
$form->field($model, 'date_start')->widget(DateTimePicker::className(), [
'options' => ['placeholder' => '-- Select Date --'],
'pluginOptions' => [
'language' => 'fr',
'autoclose' => true,
'calendarWeeks' => true,
'daysOfWeekDisabled' => [0, 5],
'todayHighlight' => true,
'todayBtn' => true,
]
]);
?>
</div>
<div class="col-sm-6">
<?=
$form->field($model, 'date_end')->widget(DateTimePicker::className(), [
'options' => ['placeholder' => '-- Select Date --'],
'pluginOptions' => [
'language' => 'fr',
'autoclose' => true,
]
]);
?>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<?=
$form->field($model, "type_evaluation_id")->dropDownList(
ArrayHelper::map(EvalTipo::find()->all(), 'id', 'description'), [
'prompt' => '-- Select Type --'
]);
?>
</div>
<div class="col-sm-3">
<?=
$form->field($model, 'duration')->widget(TimePicker::className(), [
'pluginOptions' => [
'showSeconds' => true,
'showMeridian' => false,
'minuteStep' => 1,
'secondStep' => 5,
]
]);
?>
</div>
<div class="col-sm-3">
<?=$form->field($model, 'qualification')->textInput(['placeholder' => 'Qualification']) ?>
</div>
</div>
</div>
<div class="col-sm-6">
<?=$form->field($model, 'description')->textarea(['rows' => 9, 'placeholder' => 'Enter evaluation description']) ?>
</div>
</div>
<div class="content">
<div class="box box-success box-solid">
<div class="box-header with-border">
<h3 class="box-title">Questions Evaluation</h3>
</div>
<div class="panel-body">
<?php
DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 30, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelQuestion[0],
'formId' => 'dynamic-form',
'formFields' => [
'item',
'puntuacion',
],
]);
?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Question</th>
<th style="width: 500px;">Options</th>
<th class="text-center" style="width: 90px;">
<button type="button" class="add-item btn btn-success btn-xs"><span class="glyphicon glyphicon-plus"></span></button>
</th>
</tr>
</thead>
<tbody class="container-items">
<?php foreach( $modelQuestion as $indexQuestion => $modelQuestions ): ?>
<tr class="item">
<td class="vcenter">
<table class="table table-bordered table-striped">
<td class="vcenter">1.</td>
<td class="vcenter">
<?php
// necessary for update action.
if( !$modelQuestions->isNewRecord ){
echo Html::activeHiddenInput($modelQuestions, "[{$indexQuestion}]id");
}
?>
<?=
$form->field($modelQuestion, "[{$indexQuestion}]question")->dropDownList(
ArrayHelper::map(QuestType::find()->all(), 'id', 'description'), [
'prompt' => '-- Select Question --'
]);
?>
<?=$form->field($modelQuestions, "[{$indexQuestion}]question")->label(false)->textInput(['maxlength' => true, 'placeholder' => 'Title question']) ?> <?=
$form->field($modelQuestions, "[{$indexQuestion}]score")->label(false)->widget(MaskedInput::className(), [
'clientOptions' => [
'alias' => 'decimal',
'groupSeparator' => '.',
'digits' => 0,
'autoGroup' => true,
'removeMaskOnSubmit' => true,
'rightAlign' => false,
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
])
?><?=$form->field($modelQuestions, "[{$indexQuestion}]justified ")->checkbox(array('label' => '', 'labelOptions' => array('style' => 'padding:5px;'),))->label('You want a response justified ?'); ?>
</td>
</table>
</td>
<td>
<?=
$this->render('_form-opc', [
'form' => $form,
'modelQuestion' => $indexQuestion,
'modelsOpc' => $modelsOpc[$indexQuestion],
])
?>
</td>
<td class="text-center vcenter" style="width: 90px; verti">
<button type="button" class="remove-item btn btn-danger btn-xs"><span class="glyphicon glyphicon-minus"></span></button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
</div>
<div class="form-group">
<?=Html::submitButton($model->isNewRecord ? '<span class="fa fa-plus"></span> Crear' : '<span class="fa fa-edit"></span> Modificar', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Here you can see the problem.
problem Maskinput validation
You need to bind the MaskedInput plugin to the newly created input using javascript. You can use the afterInsert event of the wbraganca/yii2-dynamicform wrapping the call to the .inputmask() jquery plugin that the extension is based on.
on the top of your view add the following and it will start working for every newly added row
$js =<<< JS
$(".dynamicform_wrapper").on("afterInsert", function(e, item) {
$(item).find("input[name*='[price]']").inputmask({
"alias":"decimal",
"groupSeparator":".",
"digits":0,
"autoGroup":true,
"removeMaskOnSubmit":true,
"rightAlign":false
});
});
JS;
$this->registerJs($js, \yii\web\View::POS_LOAD);
yii2 submit button needs to be clicked two times in form
I have a problem where I need to check more than one submit buttons in the controller. It works but I need to click submit buttons two times.
In controller :
switch(\Yii::$app->request->post('submit')) {
case 'submit_1' :
//my code
break;
case 'submit_2' :
//my code
In view
<?= Html::submitButton('NEXT', ['name' => 'submit', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
There is an issue with using jquery reserved words as your attribute id or attribute names.
Search for "Be careful when naming form elements such as submit buttons" at
https://github.com/yiisoft/yii2/blob/master/docs/guide/input-forms.md
Search "Additional Notes" at https://api.jquery.com/submit/
Changing your submit names will fix your click twice problem:
<?= Html::submitButton('NEXT', ['name' => 'submit_next', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit_prev', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
try to change name of button as array
<?= Html::submitButton('NEXT', ['name' => 'submit[]', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit[]', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
and in your controller :
$submittedType = \Yii::$app->request->post('submit');
switch($submittedType[0]) {
//your code
}
To avoid double click disable validate on submit:
$form = ActiveForm::begin([
'validateOnSubmit' => false,
]);
I am creating a page which would hold some buttons for creating different model items loaded via modal.
I'm using this code in a view file: create-all that belongs to the controller: ProductsController
Modal::begin([
'toggleButton' => [
'label' => '<i class="glyphicon glyphicon-plus"></i> Add Product',
'class' => 'btn btn-success'
],
'closeButton' => [
'label' => 'Close',
'class' => 'btn btn-danger btn-sm pull-right',
],
'size' => 'modal-lg',
]);
$class_products = 'app\models\Products';
$productModel = new $class_products();
echo $this->render('/products/create', ['model' => $productModel]);
Modal::end();
Modal::begin([
'toggleButton' => [
'label' => '<i class="glyphicon glyphicon-plus"></i> Add branch',
'class' => 'btn btn-success'
],
'closeButton' => [
'label' => 'Close',
'class' => 'btn btn-danger btn-sm pull-right',
],
'size' => 'modal-lg',
]);
$class_branch = 'app\models\Branch';
$branchModel = new $class_branch();
echo $this->render('/branch/create', ['model' => $branchModel]);
Modal::end();
branch/create code:
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model app\models\Branch */
$this->title = Yii::t('app', 'Create {modelClass}', [
'modelClass' => 'Branch',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Branches'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="branch-create">
<?php
//echo Yii::$app->request->getReferrer();
$route = parse_url(Yii::$app->request->getReferrer(), PHP_URL_QUERY);
if ($route == urldecode('r=products%2Fcreate-all'))
print_r ($route);
?>
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
The buttons work just fine and a modal loads for both of the buttons
Problem
Add Product modal adds a new product successfully, but Add Branch doesn't. It just refreshes the page.
An attempt to solve your issue:
As far as I know, simply rendering view file inside the view, will not post data to the controller, unless you specify the action inside the form which you are rendering.
So inside the _form.php
<?php $form = ActiveForm::begin([
'action'=>'your_path_to_the_url',
]); ?>
You can also make an ajax submission from the form and handle the ajax data using Yii::$app->request->isAjax
This is just an idea. I have not seen your controller code nor your forms. Still a wild guess of the problem. See this will help you or not.
this my view file for a signin page
<?php $form = ActiveForm::begin(); ?>
<?= $form->field( $model, 'email' )->textInput( [ 'maxlength' => 200 ], [ 'id' => 'email' ] ) ?>
<?= $form->field( $model, 'password' )->passwordInput( [ 'maxlength' => 200 ] ) ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-14">
<?= Html::submitButton( 'Login',
[ 'class' => 'btn btn-danger btn-block btn-lg', 'name' => 'login-button' ] ) ?>
</div>
</div>
<input type='sub' name='submit' value='Reset Password' class="btn btn-link btn-default" '>
<?php ActiveForm::end(); ?>
it works perfectly but you have to click on the login button twice. there is no other problem in signing in. i don't have a clue why i have to click the login button twice.
Firstly You've got syntax in your input type='sub' at the end You've got ' instead of /. You should render it by Html::input, then you'll avoid syntax.
Secondly change this input name. name='submit' brookes ActiveForm. Not sure why...
name='submit' is your problem here. Change it to name='not_submit' and all will be well.
The post here explains why name='submit' causes problems for ActiveForm.
Yii2 form submit button must be clicked two times for action. How to prevent this?