Update 2 containers using Pjax - yii2

I'm working on a transport planner in Yii2.
The tasks are shown in a GridView.
Above the GridView I have a navigation to go through the dates.
like so:
<?php Pjax::begin(['enablePushState' => false]); ?>
<ul id="planner_nav">
<li>
<?= Html::a('', ['planner/previous'], ['class' => 'btn btn-default glyphicon glyphicon-arrow-left pull-left']) ?>
</li>
<li>
<?= Html::a(Yii::t('app', $session->get('date')), ['#'], ['class' => 'planner_date']); ?>
</li>
<li>
<?= Html::a('', ['planner/next'], ['class' => 'btn btn-default glyphicon glyphicon-arrow-right pull-right']) ?>
</li>
</ul>
<?php Pjax::end(); ?>
As you can see the current date is stored in a session.
The date is set using DateTime().
In my actionIndex in the Planner-model I pass the datesession to the PlannerSearch-model like:
$dataProvider = $dataModel->data(Yii::$app->request->queryParams, $session->get('datum'));
And then grab the session: PlannerSearch::search($params, $date), and use the $date variable in my query.
Maybe a terrible way of doing things, but I'm still a Yii (mvc) beginner..
What I actually want to achieve, is to go through the dates and update both the planner navigation date (.planner_date) and the GridView in the planner-view with the tasks for that day.
Anyone who can help?

Related

How to write the material design radio button in yii2?

I am facing issue with material design radio button using in yii2.
this is the material design radio button which is working perfectly
<div class="radio">
<label>
<input type="radio" name="q_option" value="Recent advances in MS">
Recent advances in MS
</label>
</div>
but when I write the same radio button in yii2 framework, the radio button dot become disappear and become non clickable
<div class="radio">
<?= $form->field($model, 'q_option')->radio(
['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS']
) ?>
</div>
please guide me. Thanks a lot in advance.
Maybe be you mean radio buttons? Single radio doesnt have mean.
//controller
$model = new Cities();
return $this->render('index', [
'model' => $model,
]);
//view <?php
use yii\bootstrap\ActiveForm;
?>
<?php $form = ActiveForm::begin() ?>
<div class="radio">
<?= $form->field($model, 'city_name')->radio(
['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS']
) ?>
</div>
<?php $form::end() ?>
work well
You use $model and table_field_name. Maybe you tried use radio button list? Like that:
//view
$model = new Cities();
return $this->render('index', [
'model' => $model,
'array' => Cities::find()->all(),
]);
//controller
<?php
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
?>
<?php $form = ActiveForm::begin() ?>
<?= $form->field($model, 'city_name')
->radioList(ArrayHelper::map($array, 'id', 'city_name')) ?>
<?php $form::end() ?>

Login form requires second click to submit

My backend login form submits with a single click of the login button. It creates an <input type="hidden" name="login-button"> element then shortly thereafter submits. On the frontend the same is created on click but never posts the data until I click the button again.
Here is a sample of the view code:
<div id="login-form" class="col-sm-12">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="col-sm-5 col-sm-offset-4 forgotPassword">
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div style="margin:auto;color:#fff;margin:1em 0;font-size:10px;">
if you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>
</div>
<div class="form-group">
<?= Html::submitButton('login', ['class' => 'btn btn-primary loginButton', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
The only difference I am seeing between the two is that there are some additional <div> tags that have been added for styling purposes. I have even removed those and I am still seeing the same issues.
Any ideas would be appreciated.
It looks like the id on the form div was causing the issue. Removing this has cleared everything up.
It was causing a conflict because it had the same id as the form.
I just want to add that usually you assign model "formName" as your form id
<?php $form = ActiveForm::begin(['id' => $model->formName()]); ?>

Yii2 Add a Form field not in model

As we know,
<?= $form->field($model, 'name_field')->textInput() ?>
Adds a text field connected to 'name_field' in the model/table.
I want to add a field NOT in the model/table, and then run some JS when it loses focus to calculate the other fields.
How firstly do you add a free text field not connected to the model ?
Second, does anyone have any examples of adding JS/Jquery to the _form.php ?
The Html class contains the functions for generation of fields. In fact, your code above ends up calling Html::textInput(). To add a field
<?= Html::textInput("name", $value) ?>
To add javascript to a view just use registerJs():
$this->registerJs("alert('true');");
You can have the field rendered the same way as the ActiveField, with a label and classes. For example, let’s add a Cc field to a Mail form.
First display the To: field (in the model):
<?= $form->field($model, 'to')->textInput() ?>
Let’s add the Cc field (not in the model):
<?= Html::beginTag('div', ['class' => 'form-group field-mail-cc']) ?>
<?= Html::label('Cc:', 'mail-cc', ['class' => 'control-label']) ?>
<?= Html::textInput('Mail[cc]', '', ['id' => 'mail-cc', 'class' => 'form-control']) ?>
<?= Html::endTag('div') ?>
The class and id names mail-cc and field-mail-cc follow the ActiveForm naming pattern. The input name Mail[cc] adds your field to the ActiveForm group, so you can easily retrieve it with the usual
$form = Yii::$app->request->post('Mail');

How to use datepicker in yii2 basic?

I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<div class="row">
<div class="col-lg-6">
<div class="myproj-index">
<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
<? //$form->field($model, 'periodfrom')
echo DatePicker::widget([
'model' => $model,
'attribute' => 'periodfrom',
'language' => 'en',
'dateFormat' => 'yyyy-MM-dd',
]);
?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
Edit
I downloaded this file here jui
I found out that in my file I have no jui folder under yiisoft folder. My question in appasset how can I declare this files ?
Answer
I fixed it, I downloaded the jquery-ui files then added them to the bower folder in yii2.
First install this extension through composer.
run: php composer.phar require --prefer-dist yiisoft/yii2-jui "*" in your project directory.
update composer.
In your view file use use yii\jui\DatePicker;.
You probably did not install Datepicker in the vendor package.
Thanks.
Do you have use .....\DatePicker; ?
Also are you including the jui asset and everything, take a look at the source, do you have jui and all the JS included?
Edit:
Have you done a "composer update" lately?
Use this code if you are using kartik datetime picker
<?= $form->field($model, 'date')->widget(DatePicker::classname(),['options' => ['placeholder' => 'Enter event time ...'],'pluginOptions' => [....]]) ?>

Different sidebars for different pages on Wordpress

I'm trying to design a theme on WordPress (version 3.3.2) but I am having a few problems in having the sidebar display a different set of widgets on certain pages.
I have tried several online tutorials and this one in particular http://www.rvoodoo.com/projects/wordpress/wordpress-tip-different-sidebars-on-different-pages/ but unfortunately there is no change in the sidebar when I move to a different page
I registered two sidebars on my functions.php as shown below, one which I would consider as main, and the other as a custom sidebar, and I also added different widgets to these sidebars.
<?php register_sidebar( //register sidebar
array(
'name' => 'Right-side',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
register_sidebar( //register second sidebar
array(
'name' => 'Second-right',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
?>
Following that, I created the files sidebar.php and sidebar-second.php to be able to call them.
sidebar.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right-side')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
sidebar-second.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Second-right')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
And then I added replace my <?php get_sidebar() ; ?> statement with following conditional
<?php if( is_page('225') ) : ?>
<?php dynamic_sidebar('second'); ?>
<?php else : ?>
<?php get_sidebar() ; ?>
<?php endif ; ?>
However only the widgets added to the sidebar.php are displayed on every page. Any help on how I could change this, or pointers on what I could be doing wrong. Thanks.
I looks like you are using <?php dynamic_sidebar('second'); ?> where you should be using <?php get-sidebar('second'); ?>
What get_sidebar('foo') does is look for a file named 'sidebar-foo.php' in the root directory of your theme and includes it. dynamic_sidebar('bar'), on the other hand, looks for a sidebar registered with:
<?php register_sidebar( array( 'name' => 'bar' ... ) ) ?>
Hope this helps!
Why don't you use the Custom Sidebar Plugin?
It's really easy to use and does not need any coding
You have two sidebars. when you want to use the sidebar-second file on a particular page, instead of calling
<?php get_sidebar('second') ; ?>
TRY
<?php get_sidebar('sidebar-second.php') ; ?>
this should do the trick