I want to make a dropdown button and when I tried to make it, the position of dropdown list not in the center.
Here is my code:
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\bootstrap\Dropdown;
/* #var $this yii\web\View */
?>
<div class="site-index">
<div class="jumbotron">
<h1>Selamat Datang!</h1>
<p class="lead-lg-5">
Aplikasi ini ditujukan untuk menampilkan <br>
data-data dan statistik mahasiswa program Pascasarjana Universitas
</p>
<div class="col-md-12 school-options-dropdown text-center">
<div class="dropdown btn-group"> <div class="btn btn-success btn-sm">
Pilih Tahun Periode<b class="caret"></b>
<?php
echo Dropdown::widget([
'items' => [
['label' => 'Periode 2001-2005', 'url' => "index.php?r=site%2Findexumum"],
['label' => 'Periode 2006-2010', 'url' => '#'],
['label' => 'Periode 2011-2015', 'url' => '#'],
],
]);
?>
</div>
</div>
</div>
</div>
</div>
Here is the result:
What may I do to solve that? Thanks in advance
Related
In Yii2, I have been trying to create a dynamic form using the below tutorials.
Yii2-dynamicForm - GitHub and Youtube Tutorial.
I followed the same step as mentioned in tutorials, unfortunately I am held up with an error(screenshot attached)
And I am not able to resolve this error, can any one help me to find what I am missing.
For the reference I am attaching my Models here, rest the controllers and views are same as the tutorials.
Request Model
<?php
namespace app\models;
use Yii;
class Request extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'request';
}
public function rules()
{
return [
[['req_date', 'req_on', 'req_updated_on'], 'safe'],
[['req_job', 'req_type', 'material_type', 'req_status'], 'required'],
[['req_by'], 'integer'],
[['req_status'], 'string'],
[['req_job', 'req_type'], 'string', 'max' => 100],
[['material_type'], 'string', 'max' => 150],
];
}
public function attributeLabels()
{
return [
'req_id' => 'Req ID',
'req_date' => 'Req Date',
'req_job' => 'Job No',
'req_type' => 'Type of Request',
'req_on' => 'Required On',
'material_type' => 'Material Type',
'req_by' => 'Req By',
'req_updated_on' => 'Req Updated On',
'req_status' => 'Request Status',
];
}
}
RequestItems Model
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* This is the model class for table "request_items".
*
* #property int $req_item_id
* #property int $req_id
* #property string $item_name
* #property string $item_qty
* #property string $item_unit
*/
class RequestItems extends \yii\db\ActiveRecord
{
/**
* {#inheritdoc}
*/
public static function tableName()
{
return 'request_items';
}
/**
* {#inheritdoc}
*/
public function rules()
{
return [
[['req_id', 'item_name', 'item_qty', 'item_unit'], 'required'],
[['req_id'], 'integer'],
[['item_name'], 'string', 'max' => 100],
[['item_qty', 'item_unit'], 'string', 'max' => 25],
];
}
/**
* {#inheritdoc}
*/
public function attributeLabels()
{
return [
'req_item_id' => 'Req Item ID',
'req_id' => 'Req ID',
'item_name' => 'Item Name',
'item_qty' => 'Item Qty',
'item_unit' => 'Item Unit',
];
}
}
_form.php
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget;
use kartik\select2\Select2;
use kartik\checkbox\CheckboxX;
/* #var $this yii\web\View */
/* #var $model app\models\Request */
/* #var $form yii\widgets\ActiveForm */
?>
<div class="request-form">
<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
<?= $form->field($model, 'req_date')->hiddenInput()->label(false) ?>
<div class="row">
<div class="col-sm-6">
<?php
$data = ['1001' => '1001/Sample Job 1', '1002' => '1002/Sample Job 2', '1003' => '1003/Sample Job 3'];
echo $form->field($model, 'req_job')->widget(Select2::classname(), [
'data' => $data,
'class'=>'form-control',
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]); ?>
</div>
<div class="col-sm-6">
<?= $form->field($model, 'req_type')->radioList(array('Urgent'=>'Urgent','Normal'=>'Normal')); ?>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<?= $form->field($model, 'req_on')->input('date') ?>
</div>
<div class="col-sm-6">
<?= $form->field($model, 'material_type')->radioList(array('Civil'=>'Civil','Mechanical'=>'Mechanical', 'Manpower'=>'Manpower')); ?>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<?= $form->field($model, 'req_by')->hiddenInput()->label(false) ?>
</div>
<div class="col-sm-6">
<?= $form->field($model, 'req_updated_on')->hiddenInput()->label(false) ?>
</div>
</div>
<!-- code for dynamic form -->
<div class="panel panel-default">
<div class="panel-heading"><h4><i class="glyphicon glyphicon-envelope"></i> Request Items</h4></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' => 4, // 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' => $modelsAddress,
'formId' => 'dynamic-form',
'formFields' => [
'item_name',
'item_qty',
'item_unit',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsAddress as $i => $modelAddress): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Requested Items</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelAddress->isNewRecord) {
echo Html::activeHiddenInput($modelAddress, "[{$i}]id");
}
?>
<?= $form->field($modelAddress, "[{$i}]item_name")->textInput(['maxlength' => true]) ?>
<div class="row">
<div class="col-sm-6">
<?= $form->field($modelAddress, "[{$i}]item_qty")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-6">
<?= $form->field($modelAddress, "[{$i}]item_unit")->textInput(['maxlength' => true]) ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
<?= $form->field($requestModel, 'req_status')->dropDownList(['Requested' => 'Requested', 'Approved' => 'Approved', 'Rejected' => 'Rejected', 'Hold' => 'Hold',], ['prompt' => '']) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
You need to change the
'model'=>$modelsAddress
to
'model'=>$modelsAddress[0]
As stated in the basic example, its an array of models and the way you passing, it will be detected as array rather than a model.
I have two activeform in my view and one of them use pjax. And both of them requires second click to submit. I don't know what I am doing wrong. I search this problem in internet, but meet other cases of second click
<?php Pjax::begin(['id' => 'workers', "timeout" => 50000], ["options" => ["timeout" => 5000]]);?>
<?php
echo $this->render('_show', [
"model" => $searchModel,
"filials" => $filials,
"workers" => $workers,
"posts" => $posts,
]);
echo $this->render('_handle_form');
?>
<div class="row js-loader">
<div class="col-lg-12 col-md-12">
<div class="table-responsive">
<?=GridView::widget([
'dataProvider' => $dataProvider,
'emptyText' => 'Нет результатов',
'tableOptions' => ['class' => 'table table-hover table-claim table-claimadm', 'style' => 'font-weight:600;'],
'rowOptions' => ['class'=>'row-without-border row-open'],
'layout' => "{items}{pager}",
'columns' => [
[
...
]
]);?>
</div>
</div>
</div>
<?php Pjax::end();?>
<script>
window.onload = function () {
$(document).on('pjax:send', function (event) {
tbody = $('#' + event.target.id).find(".js-loader");
if (tbody.length != 0) {
tbody_height = tbody.height();
tbody.html('<div class="block-loader" style="width:100%"></div>');
}
});
$('#submit_with_answer').click(function() {
if ($.trim($('#text-claim').val()).length > 0)
{
$('#complaint_feedback').submit();
}
else
{
$('#textarea-group').addClass('has-error');
$('#answer_error').html('Заполните поле «Добавить текст ответа»');
}
});
};
</script>
The "_show" view is:
<?php $form = ActiveForm::begin([
'id' => 'complaints',
'action' => Url::to(['complaints/show']),
'method' => 'GET',
'options' =>
[
'class' => 'form-respons form-claimadm',
'data-pjax' => 1,
],
]);
active fields....
<div class="form-btns col-md-2 col-sm-6 col-xs-12">
<?= Html::submitButton('Применить', ['class' => 'btn btn-primary','style'=>"float:right;"]) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
and _handle_form is:
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<?php
$form = ActiveForm::begin([
'id' => 'complaint_feedback',
'action' => Url::to(['complaints/handle-complaint']),
'method' => 'POST',
'options' => ['class' => 'form-respons form-claim-feedback','style'=>'display:none;'],
]);
?>
<div id="textarea-group" class="form-group">
<label for="text-claim" class="hidden-xs">Добавить текст ответа</label>
<textarea class="form-control" id="text-claim" rows="3" name="complaint_answer" placeholder="Добавить текст ответа"></textarea>
<div id="answer_error" class="help-block"></div>
<input id="complaint_id" name="complaint_id" type="hidden" value="">
</div>
<div class="clearfix form-btns">
<button type="button" onclick="$('#complaint_feedback').submit();" class="btn btn-link">Обработать без ответа</button>
<button id="submit_with_answer" type="button" class="btn btn-primary">Отправить</button>
</div>
<?php ActiveForm::end(); ?>
<a id="hide_handle_form" style="display: none;" onclick="$('#complaint_feedback').hide(); $('.handle_button').removeClass('disabled'); $(this).hide();$('tr[data-key='+$('#complaint_id').val()+']').removeClass('row-open');" class="btn btn-link btn-show-hide">Свернуть
</a>
if I comment lines with pjax, everything works correctly. How can I fix this trouble?
I have my dynamic form using wbraganca widget and kartik file upload inside it. When I open the page, the field was just showing spinner image instead of a textfield and the console display "unrecognized expression: #tcandidateexp-{$i}-prod_per_year_file". The field I want to use as a file upload is "prod_per_year_file". Any help would be appreciate. Thanks.
<?php $form = ActiveForm::begin(['id' => 'dynamic-form', 'options'=>['enctype'=>'multipart/form-data']]); ?>
<div class='row'>
<?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' => 5, // the maximum times, an element can be added (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $models_exp[0],
'formId' => 'dynamic-form',
'formFields' => [
'start_year',
'end_year',
'company',
'prod_per_year',
'prod_per_year_file',
'inc_per_year',
'inc_per_year_file'
],
]); ?>
<div class="panel panel-default" style="width:85%">
<div class="panel-heading">
<h4>
<i class="glyphicon glyphicon-envelope"></i> Experiences
<button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
</h4>
</div>
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
<?php foreach ($models_exp as $i => $model_exp): ?>
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Detail</h3>
<div class="pull-right">
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $model_exp->isNewRecord) {
echo Html::activeHiddenInput($model_exp, "[{$i}]id");
}
?>
<div class="row">
<div class="col-sm-6" >
<?=
$form->field($model_exp, "[{$i}]start_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]end_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]company")->textInput();
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]prod_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?php
//$form->field($model_exp, "[{$i}]prod_per_year_file")->textInput()
echo $form->field($model_exp, '[{$i}]prod_per_year_file')->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year_file")->textInput() ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
</div>
Try replace the single quotes with double quotes
echo $form->field($model_exp, "[{$i}]prod_per_year_file")->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
I have a page which consist of 5 tab. 1st and 2nd tab is just normal filling form while my 3rd,4th and 5th tab is the index of other index page (which I can create update and delete the data). Below is the code for the form.
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\tabs\TabsX;
use kartik\date\DatePicker;
use frontend\models\OpStates;
use frontend\models\OpContact;
use frontend\models\OpCountries;
use frontend\models\OpClient;
use frontend\models\OpUnit;
use frontend\models\OpMaintenanceCharges;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
$this->title = 'Change Profile';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-changedetails">
<?php $form = ActiveForm::begin(['id'=>'changedetails-form',]); ?>
<?= TabsX::widget([
'position' => TabsX::POS_ABOVE,
'align' => TabsX::ALIGN_LEFT,
'items' => [
[
'label'=>'Client Details',
'content'=>
'<div class="row">
<div class="col-md-12">'.
$form->field($model, "client_code")->textInput(["maxlength" => true]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "contact_id")->dropDownList(ArrayHelper::map(OpContact::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "unit_id")->dropDownList(ArrayHelper::map(OpUnit::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'country_id')->dropDownList(ArrayHelper::map(OpCountries::find()->all(),'id','name'),
[
'prompt' => 'Select Country',
'onchange' => '
$.post("index.php?r=op-states/lists&id='.'" + $(this).val(), function(data){
$("select#opclient-states_id").html(data);
});'
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'states_id')->dropDownList(ArrayHelper::map(OpStates::find()->all(),'id','state_name'),
[
'prompt' => 'Select States',
]).'
</div>
</div>
<div class="row">
<div class="col-md-6">'.
$form->field($model, 'city')->textInput(['maxlength' => true]).'
</div>
<div class="col-md-6">'.
$form->field($model, 'postcode')->textInput().'
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-1 col-md-offset-11">'.
Html::submitButton('Save',['class'=>'pull-right btn btn-primary','style'=>'width:70px; height:40px;','name'=>'button1']).'
</div>
</div>
</div>
'
],
[
'label'=>'Client Details 2',
'content'=>
' <div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_interest")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'interest_effective_date')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd',
'todayHighlight' => true,
'todayBtn' => true,
]
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_reminder")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "external_debtor_code")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address1")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address2")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address3")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address4")->textInput().'
</div>
</div>
'
],
[
'label'=>'Maintenance Charges',
'content' => $this->render('//op-maintenance-charges/index', [
'model'=>$model,
'dataProviderMainCharges' => $dataProviderMainCharges,
]),
],
[
'label'=>'Misc Charges',
'content' => $this->render('//op-misc-charges/index', [
'model'=>$model,
'dataProviderMiscCharges' => $dataProviderMiscCharges,
]),
],
[
'label'=>'Occupier Details',
'content' => $this->render('//op-occupier/index', [
'model'=>$model,
'dataProviderOccupier' => $dataProviderOccupier,
]),
],
]
]); ?>
<?php ActiveForm::end(); ?>
The problem is the 1st index page is working normally. Click to see - Working normally
The 2nd index page n 3rd index cannot work. The form wont even come out. The screen just become darker and I cant click anything like this Click to see - Cant Work
Anyone can help or have any idea on how to fix it? Thanks
im trying to print an attribite from another table in yii2 Listview but im not able to get the data i need to print into the listview
$query = Producto::find()->joinWith(['mPrecios']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 6,
],
]);
Data Provider in search model
$searchModel = new ProductoSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$modelCliente=new Cliente;
$cliente = Cliente::getClientes();
$rows = Producto::autocomplete();//Se envia la variable que contiene los productos a la vista
return $this->render('index', array(
'rows'=>$rows,
'model' => $model,
'modelC'=>$modelCliente,
'searchModel' => $searchModel,
'clientes'=>$cliente,
'listDataProvider' => $dataProvider
)
);
Send DtaProvider through Controller
<?php \yii\widgets\Pjax::begin(['id'=>'listaProductos','enablePushState' => true, 'timeout' => 8000000, 'clientOptions' => ['container' => 'pjax-container']]); ?>
<?=
ListView::widget([
'options'=>[
'class'=>'col-lg-12 list-wrapper inline row-eq-height',
],
'dataProvider' => $listDataProvider,
'itemView' => function ($model, $key, $index, $widget) {
$itemContent = $this->render('_tabla_producto',['model' => $model]);
return $itemContent;
},
'itemOptions' => [
'tag' => false,
],
'summary' => '',
'layout' => '{items}{pager}',
'pager' => [
'firstPageLabel' => 'Primera',
'lastPageLabel' => 'Ultima',
'maxButtonCount' => 5,
'options' => [
'class' => ' pagination col-xs-12'
]
],
]);
?>
<?php \yii\widgets\Pjax::end(); ?>
ListView
<?php $IdProducto = $model['Refe'];?>
<div id="producto-<?php echo $IdProducto;?>" class="content inline producto col-lg-4 box-body" >
<div class="row">
<div class="col-lg-6">
<img class='img-responsive' src="<?php echo $model['ImagenProducto']?>"/>
</div>
<div class="row">
<div class="col-lg-6" style="height:200px;">
<?php
if($model['Fraccion'] > 1){
echo "<button id='fraccion-$IdProducto' class='btn btn-danger btn-xs fraccionado' data-toggle='modal' data-target='#modalFraccion'><b>F</b></button>";
}
else{
echo "<button id='fraccion-$IdProducto' class='btn btn-default btn-xs disabled'><b>NF</b></button>";
}
?><br>
<b>Nombre:</b><br><?= $model['DescripcionCorta'] ?><br>
<b>Presentacion:</b><br><?= $model['PresentacionCorta'] ?><br>
<b>Precio:</b> HERE GOES THE OTHER TABLE ATTRIBUTE
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-btn" >
<button id="menos-<?php echo $IdProducto;?>" type="button" class="btn btn-sm btn-default btn-minuse" min='0' value="0">-</button>
</span>
<input id="input-<?php echo $IdProducto;?>" type="text" value="0" class="form-control text-center" style="height:30px;">
<span class="input-group-btn">
<button id="mas-<?php echo $IdProducto;?>" type="button" class="btn btn-sm btn-default btn-pluss" min='0' value="0">+</button>
</span>
</div>
</div>
<div class="col-lg-6 pull-left">
<button id="anadir-<?php echo $IdProducto;?>" type="button" class="text-center center-block btn btn-sm btn-default btn-add">Añadir</button>
</div>
</div>
</div>
I will assume you have your relation set up correctly in your model, getMPrecios().
If this is a hasOne() you can access the relational data with $model->mPrecios->attributeName and if its a hasMany() you'll have to do a
foreach($model->mPrecios as $mprecios)
{
echo $mprecios->attributeName;
}
This relational values should be accessible regardless of whether you eagerly load them (like you do with a joinWith()) or lazy load them.