2amigos DataRangePicker. Display over input. - twitter-bootstrap-3

Problem
I set orientation, but it's still at the bottom. What's the problem?
Code
<?=$form->field($contactUsModel, 'planningToTravelFrom')
->widget(\dosamigos\datepicker\DateRangePicker::className(), [
'attributeTo' => 'planningToTravelTo',
'form' => $form, // best for correct client validation
'language' => 'es',
'size' => 'lg',
'clientOptions' => [
'autoclose' => true,
'orientation' => 'top',
'format' => 'dd-M-yyyy'
]
]);?>

Problem was in
Should be 'orientation' => 'bottom'
Not works with date-range-picker bugfix
$("#contactform-planningtotravelfrom, #contactform-planningtotravelto").datepicker().on('show.bs.modal', function (event) {
// prevent datepicker from firing bootstrap modal "show.bs.modal"
event.stopPropagation();
});

Related

How to add 'sub elements' in Zend Form

I have a Zend Form with several fields for the user to complete. In the admin system I want to display the exact same form but with additional Elements next to the existing ones where the administrator will be able to provide feedback to the user's input.
Below you can see the code I am using to create the form that the user sees.
Before posting this question I had a look on Zend Form Decorator but I did not understand if that's what I need to resolve this issue.
public function __construct()
{
parent::__construct('user-feedback-form');
$this->setAttribute('method', 'post');
$this->setAttribute('role', 'form');
$this->add([
'name' => 'name',
'type' => Text::class,
'attributes' => [
'id' => 'name',
'required' => true,
'readonly' => false,
],
]);
$this->add([
'name' => 'surname',
'type' => Text::class,
'attributes' => [
'id' => 'surname',
'required' => true,
'readonly' => false,
],
]);
$this->add([
'name' => 'age',
'type' => Number::class,
'attributes' => [
'id' => 'age',
'required' => true,
'readonly' => false,
],
]);
}
To reuse certain parts of a form zend provides the fieldsets.
Instead of adding the elements to your form add them toa filedset and add the fieldset to the form.
class UserFeedbackFieldset extends Zend\Form\Fieldset
{
public function init()
{
$this->add([
'name' => 'name',
'type' => Text::class,
'attributes' => [
'id' => 'name',
'required' => true,
'readonly' => false,
],
]);
$this->add([
'name' => 'surname',
'type' => Text::class,
'attributes' => [
'id' => 'surname',
'required' => true,
'readonly' => false,
],
]);
$this->add([
'name' => 'age',
'type' => Number::class,
'attributes' => [
'id' => 'age',
'required' => true,
'readonly' => false,
],
]);
}
}
Then in your forms add the fieldset:
class UserFeedbackForm extends Zend\Form\Form
{
public function __construct()
{
parent::__construct('user-feedback-form');
$this->setAttribute('method', 'post');
$this->setAttribute('role', 'form');
}
public function init()
{
$this->add([
'type' => UserFeedbackFieldset::class,
'name' => 'user',
'options' => [
'use_as_base_fieldset' => true,
],
]);
}
}
class AdminUserFeedbackForm extends Zend\Form\Form
{
public function __construct()
{
parent::__construct('user-feedback-form');
$this->setAttribute('method', 'post');
$this->setAttribute('role', 'form');
}
public function init()
{
$this->add([
'type' => UserFeedbackFieldset::class,
'name' => 'user',
'options' => [
'use_as_base_fieldset' => true,
],
]);
$this->add([
'name' => 'someotherfield',
'type' => Text::class,
'attributes' => [
'id' => 'someotherfield',
'required' => true,
'readonly' => false,
],
]);
}
}
Then you can use the other form on your admin page instead of the original one.

Displaying an image in kartik grid shows the path

I have a grid and i would like to implement an image but it always returns the path to the image
this is the code:
[
'attribute' => 'picture',
'value'=>function($data) { return $data->imageurl; },
'value' => function ($data) {
return Html::img(Yii::getAlias('#web').'/images/user_accounts.png',
['width' => '70px']);
},
],
The above idea i got from This link but it fails
I have also tried :
[
'attribute' => 'picture',
'value'=>function($data) { return $data->imageurl; },
],
And added
public function getImageurl()
{
return \Yii::$app->request->BaseUrl.'/images/user_accounts.png';
}
But it still fails to display the image to the grid
This is what is displayed
Try this:
[
'attribute' => 'picture',
'format' => 'html',
'value' => function ($data) {
return Html::img(Yii::getAlias('#web').'/images/'. $data['imageurl'],
['width' => '70px']);
},
],
Use the format attribute of the DataColumn class, by default it uses the text format, so the content is displayed as text instead of html. Use the raw or html formatters
>>>This may be helpfull too...
[
'attribute' => 'picture',
'format' => 'html',
'value' => function ($data) {
return Html::img($data->imageurl,['width' => '80px']);
},
'filterType' => GridView::FILTER_SELECT2,
'filter' => '',
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Image Url'],
],

Automatically refreshing yii2 grid after server database changes

I have a grid that involves truck verification. I would like the contents of the grid to change without page refresh.
Currently this works when the page is refreshed but i would like it to work even when a page is not refreshed that is when the content changes in the server database.
This is the grid
<?php
$gridColumns = [
['class' => 'kartik\grid\SerialColumn'],
'reg_no',
[
'attribute'=>'truck_category',
'value'=>'truckCategory.category'
],
[
'class' => 'kartik\grid\ActionColumn',
'vAlign'=>'middle',
'urlCreator' => function($action, $model, $key, $index) { return '#'; },
'viewOptions'=>['title'=>"vdgdv", 'data-toggle'=>'tooltip'],
'updateOptions'=>['title'=>"update", 'data-toggle'=>'tooltip'],
'deleteOptions'=>['title'=>"delete", 'data-toggle'=>'tooltip'],
]
];
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false
'beforeHeader'=>[
[
'options'=>['class'=>'skip-export'] // remove this row from export
]
],
'toolbar' => [
[],
'{export}',
'{toggleData}'
],
'pjax' => true,
'bordered' => true,
'striped' => false,
'condensed' => false,
'responsive' => true,
'hover' => true,
'floatHeader' => true,
'showPageSummary' => true,
'panel' => [
'type' => GridView::TYPE_PRIMARY
],
]);
?>
This is the controller that renders the grid
public function actionTrackingcenter()
{
$query = Truck::find()->where(['truck_status'=>5]);
$searchModel = new TruckSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams,$query);
return $this->render('trackingcenter/index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Could someone give a direction on how i can achieve the automatic change
You can use below with set-time-interval with jQuery
<?php
$this->registerJs('
setInterval(function(){
$.pjax.reload({container:"YOUR_PJAX_CONTAINER_ID"});
}, 10000);', \yii\web\VIEW::POS_HEAD);
?>
This code will be place after your GridView code
This will be reload your Pjax grid every 10 second

CakePHP 3.2: Prevent authError showing when user is not logged in

Even when user is not logged in and tries to open homepage, after being redirected to login page, authError is displayed.Is there an elegant way to prevent this, without modifying Auth component? This is how I load Auth component(I am using TinyAuth as authorization adapter):
$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'loginRedirect' => [
'controller' => 'Home',
'action' => 'index'
],
'authError' => 'You dont have permissions for that action',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'scope' => ['Users.active' => true],
'contain' => ['Roles']
]
],
'authorize' => [
'TinyAuth.Tiny' => [
'roleColumn' => 'role_id',
'rolesTable' => 'Roles',
'multiRole' => true,
'pivotTable' => 'roles_users',
'superAdminRole' => null,
'authorizeByPrefix' => false,
'prefixes' => [],
'allowUser' => false,
'adminPrefix' => null,
'autoClearCache' => true
]
]
]
);
According to CakePHP's documentation you can prevent the error message from being shown by setting authError to false.
Sometimes, you want to display the authorization error only after the
user has already logged-in. You can suppress this message by setting
its value to boolean false.
This should disable the error message:
if (!$this->Auth->user()) {
$this->Auth->config('authError', false);
}

click yii2 gridview linkpager's page no, jump error

the gridview if on right of the page,left is some menus,when click on page no 2,it dose not only refresh the gridview,but all page including left part are lost——a totally new page come out!help~
there is the debugging Screenshot:
my action is
public function actionList()
{
$model = new Loan();
$dataProvider = new ActiveDataProvider([
'query' => $model->find(),
'pagination' => [
'pagesize' => '1',
],
]);
return $this->renderPartial('list', ['model' => $model, 'dataProvider' => $dataProvider]);
}
my view is:
<?php
use yii\grid\GridView;
use yii\grid\SerialColumn;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<?=GridView::widget([
'dataProvider' => $dataProvider,
'layout'=> '{items}{pager}',
'columns' => [
['attribute' =>'loan_type','label'=>'借款类型','options' => ['width' => '80']],
['attribute' =>'amount','label'=>'金额','options' => ['width' => '80']],
['attribute' =>'rate','label'=>'还款利率','options' => ['width' => '80']],
['attribute' =>'fee','label'=>'手续费','options' => ['width' => '80']],
['attribute' =>'status','label'=>'状态','options' => ['width' => '80'] ],
['attribute' =>'comment','label'=>'审核意见','options' => ['width' => '80']],
['attribute' => 'created_at','value' =>function($model){return date('Y-m-d',strtotime($model->created_at));},'label'=>'申请时间','options' => ['width' => '150']],
[
'class' => 'yii\grid\ActionColumn',
'header' => '操作',
'template' => '{audit}',
'buttons' => [
'audit' => function ($url,$model) {
return Html::a('<span id="xxxx" class="glyphicon glyphicon-user"></span>','#',['title'=>'审核',
'onclick'=>"
$.ajax({
type: 'GET',
dataType: 'text',
url: 'http://182.92.4.87:8000/index.php?r=loan/pj', //目标地址
error: function (XMLHttpRequest, textStatus, errorThrown) {alert(XMLHttpRequest.status + ':' + XMLHttpRequest.statusText); },
success: function (page)
{
$('.ucRight').html(page);
}
});
return false;",
]);},
],
'urlCreator' => function ($action, $model, $key, $index) {
return Yii::$app->getUrlManager()->createUrl(['loan/list','id' => $model->status]);
},
'headerOptions' => ['width' => '80'],
],
],
]);
?>
The reason for your problem is that you haven't prevented the html link from directing to a new page, so your user is clicking on the link, which then loads a new page with the contents returned by the server; in this case a page of information with no layout applied. You need to add event.preventDefault() before the ajax call to stop this behaviour.
However, as #arogachev said, if you simply want to use pagination without a page refresh, then just use pjax. That is what pjax is designed for,