Code Monkey home page Code Monkey logo

yii2-date-picker-widget's Introduction

Bootstrap DatePicker Widget for Yii2

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Renders a Bootstrap DatePicker plugin.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require 2amigos/yii2-date-picker-widget:~1.0

or add

"2amigos/yii2-date-picker-widget" : "~1.0"

to the require section of your application's composer.json file.

Usage

The widget comes in two flavors:

  • DatePicker
  • DateRangePicker

DatePicker

This widget renders a Bootstrap DatePicker input control. Best suitable for model with date string attribute.

Example of use with a form
There are two ways of using it, with an ActiveForm instance or as a widget setting up its model and attribute.

<?php
use dosamigos\datepicker\DatePicker;

// as a widget
?>

<?= DatePicker::widget([
    'model' => $model,
    'attribute' => 'date',
    'template' => '{addon}{input}',
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'dd-M-yyyy'
        ]
]);?>

<?php 
// with an ActiveForm instance 
?>
<?= $form->field($model, 'date')->widget(
    DatePicker::className(), [
        // inline too, not bad
         'inline' => true, 
         // modify template for custom rendering
        'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'dd-M-yyyy'
        ]
]);?>

Example of use without a model

<?php
use dosamigos\datepicker\DatePicker;
?>
<?= DatePicker::widget([
    'name' => 'Test',
    'value' => '02-16-2012',
    'template' => '{addon}{input}',
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'dd-M-yyyy'
        ]
]);?>

DateRangePicker

This widget renders a Bootstrap DateRangePicker Input control.

Example of use with a form
The following example works with a model that has two attributes named date_from and date_to.

<?php
use dosamigos\datepicker\DateRangePicker;
?>
<?= $form->field($tour, 'date_from')->widget(DateRangePicker::className(), [
    'attributeTo' => 'date_to', 
    'form' => $form, // best for correct client validation
    'language' => 'es',
    'size' => 'lg',
    'clientOptions' => [
        'autoclose' => true,
        'format' => 'dd-M-yyyy'
    ]
]);?>

Example of use without a model

<?php
use dosamigos\datepicker\DateRangePicker;
?>
<?= DateRangePicker::widget([
    'name' => 'date_from',
    'value' => '02-16-2012',
    'nameTo' => 'name_to',
    'valueTo' => '02-20-2012'
]);?>

Testing

To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do the following (assuming you have composer installed on your computer):

$ composer install --no-interaction --prefer-source --dev

Once all required libraries are installed then do:

$ vendor/bin/phpunit

I would recommend to have phpunit globally installed together with xdebug so you can have code coverage analysis too.

Further Information

Please, check the Bootstrap DatePicker site documentation for further information about its configuration options.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.

2amigOS!
Web development has never been so fun!
www.2amigos.us

yii2-date-picker-widget's People

Contributors

alex-bond avatar amigo-tabin avatar katag9k avatar naffiq avatar tonydspaniard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-date-picker-widget's Issues

No work in modal

hello guys
I'm using this extension in a modal form, the modal form loaded from ajax. The response from the ajax request is un render partial the php view declare the active form

Thanks

Is not installing properly, why?

I tried to install it by compsor and ran command.
Following errors I got and my php version is PHP 7.1.6.

The "https://bower.herokuapp.com/packages/jquery" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
Failed to enable crypto
failed to open stream: operation failed
https://bower.herokuapp.com/packages could not be fully loaded, package information was loaded from tYour requirements could not be resolved to an installable set of packages.

Problem 1
- 2amigos/yii2-date-picker-widget 1.0.7 requires bower-asset/bootstrap-datepicker 1.7.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.6 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.5 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.4 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.3 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.2 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.1 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.0 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
- Installation request for 2amigos/yii2-date-picker-widget ~1.0 -> satisfiable by 2amigos/yii2-date-picker-widget[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7].

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Installation failed, reverting ./composer.json to its original content.

Inline - No way to tell the input value changes

Hi guys,

I am passing inline => true and trying to read the value of the input as it changes. Since it is changed by jQuery('#$id').val(e.format()); there is no 'change' or similar event fired.

I had to hack around it like this:

    $('.datepicker-wrapper').on('click', function(e) { // datepicker widget does .val which does not trigger events
        if (!($(e.target).is('.day'))) { // passing '.day' as second arg to .on does not work either because the whole thing gets redrawn
            return;
        }
        setTimeout(function() { // and timeout because click happens faster than the .val
            doThingWithValue($('#datepicker-input').val());
        }, 32);
    });

I think the best solution (besides using ActiveForm, I know) would be to let me pass my own clientEvents['changeDate'] and skip this if I do pass it:

if ($this->inline) {
    $this->clientEvents['changeDate'] = "function (e){ jQuery('#$id').val(e.format());}";
}

Let me know if you want a pull request.

Mike

How to change the width of the field?

Hello,

I'm using your datetime picker, but I'm trying to change the width of the field (because it's too big) and unfortunatelly I'm not suceeding.

Can you help me?

Thank you.

Date 'format' is not respected on 'Update'.

I use widget in my _form.php that is used both by create and update actions:

        <?= $form->field($model, 'publication_date')->widget(
            DatePicker::className(), [
                'language' => 'ru',
                'clientOptions' => [
                    'autoclose' => true,
                    'format' => 'dd.mm.yyyy',
                    'todayBtn' => true,
                    'pickerPosition' => 'top-left'
                ]
        ]);?>

When I select desired date in create view, everything is fine:
screenshot_20170420_175852

But when I go to 'update' view I see that required field is rendered like this:
screenshot_20170420_175241
So, no format is respected during rendering the field.
Any ways to fix?

Installation

Hi,

I am trying to install your plugin, and I am getting errors in composer.

I installed it once before, and it was fine.

Clear button problem

Can't figure out how clear button works. Using simple configuration of widget in GridView filter:

   <?php Pjax::begin(); ?>
   <?= GridView::widget([
       'dataProvider' => $dataProvider,
       'filterModel' => $searchModel,
       'columns' => [
           ['class' => 'yii\grid\SerialColumn'],

           'id',
           'username',
           'email:email',
           'created_at:datetime',
           [
               'attribute' => 'last_login',
               'format' => 'datetime',
               'filter' => DatePicker::widget([
                   'model' => $searchModel,
                   'attribute' => 'last_login',
                   'template' => '{addon}{input}',
                   'clientOptions' => [
                       'autoclose' => true,
                       'format' => 'yyyy-mm-dd',
                       'clearBtn' => true,
                   ],
               ])
           ],

           ['class' => 'yii\grid\ActionColumn'],
       ],
   ]); ?>
   <?php Pjax::end(); ?>

Pushing clear does'nt reload GridView. Inputs val() clears, but actual attribute value - not. It seems that none of change event is firing also. Am I miss something simple? In other parts widget works just great.

Accessibility - tabindex

Hello it looks like it doesn't accept tabindex in textInput:

<?= $form->field($profile, 'birthday')->textInput([ 'tabindex' => 3])->label('Birth date')->widget(DatePicker::className(), [
'inline' => false,

'clientOptions' => [
    'autoclose' => true,
    'format'    => 'yyyy-mm-dd',
    'startDate' => '1900-01-01',
    'startView' => 2,
    'value' => 'YYYY-MM-DD',
]
]); ?>

Is this intention (to be handled by JS) or just an omitted feature?

Thanks.

autoclose not work

code

$form->field($model, 'premiere')->widget(
        DatePicker::className(), [
    // inline too, not bad                
    'inline' => true,
    'language' => 'ru',
    // modify template for custom rendering
    'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
    'clientOptions' => [
        'autoclose' => true,
        'format' => 'dd.mm.yyyy'
    ]
]);

result

http://i.imgur.com/TjGzDQ4.png
screenshot_23

Uncaught TypeError: jQuery(...).parent(...).datepicker is not a function

Hi there,

Is there a way to identify which version of jquery are you using?

Or is there anyway that I could solve this issue?

I am using a templates which have the older version of jquery

'js/jquery-1.7.2.min.js', 'js/excanvas.min.js', 'js/chart.min.js', 'js/bootstrap.js', 'js/full-calendar/fullcalendar.min.js', 'js/base.js',

If I remove the jquery here, the error won't be showing and the datepicker will be working just fine.

However, I need those jquery in order to do other stuff so it can't be removed.

Or maybe noConflict() can help?

Datepicker widget not passing validation

I used the datepicker to display date of birth with model rules and controller validate(), unfortunately validation does not work.
VIEW

     <?= DatePicker::widget([
    'model' => $model,
    'form' => $form,
    'attribute' => 'dob',
    'template' => '{addon}{input}',
        'clientOptions' => [
        'format' => 'L',
        'autoclose' => true,
        'format'  => 'yyyy-mm-dd', 
        'endDate'=> '1970-12-31', 
        ]
]);?>

MODEL RULE

[['dob'], 'required'],
[['dob'], 'date'],

CONTROLLER

if ($model->load(Yii::$app->request->post())&& $model->validate())
 {
   // save record.
}

input value doesnot change (no response) when click to select a date

The datapicker widget shows up, but clicking got no response, the value does not change at all.

Besides, language not working.

    <?= $form->field($model, 'birth_date')->widget(
        DatePicker::className(), [
            // inline too, not bad
             'inline' => true,
            // 'language' => Yii::$app->language,
             // modify template for custom rendering
            'template' => '<div class="well well-sm" style="background-color: #fff; width:150px">{input}</div>',
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'yyyy-MM-dd'
            ]
    ]);?>

Dependant Datepickers

I need to set a pickupDate and pickupDateMax, the maximum date cannot be earlier than the initial date, i disabled the maxDate and should be set until pickupDate has some value, any ideas how to accomplish that?

This are my fields

<?=
$form->field($shipment, 'pickupDate')->widget(
        DatePicker::className(), [
    'clientOptions' => [
        'autoclose' => true,
        'todayHighlight' => true,
        'language' => 'es',
        'startDate' => '0d',
        'format' => 'dd-M-yyyy'
    ]
]);
?>
<?=
$form->field($shipment, 'pickupDateMax')->widget(
        DatePicker::className(), [
    'clientOptions' => [
        'autoclose' => true,
        'todayHighlight' => true,
        'language' => 'es',
        'startDate' => '0d',
        'format' => 'dd-M-yyyy'
    ],
    'options' => [
        'disabled' => true
    ]
]);
?>

Limit date Picker to month and year, by discarding days.

Im using the date picker widget inside the gridview to filter. But i need a datepicker that shows only month and year.
I have tried many options like -
'changeMonth'=>true,
'changeYear'=>true,
'changeDay'=>false,
but not working.
This is my code:

  <?= GridView::widget([
                                'dataProvider' => $dataProvider,
                                'filterModel' => $searchModel,
                                'columns' => [
                                    'name',
                                    'otp_num',
                                    [
                                       'attribute'=> 'otp_created_date',
                                         'value'=>'otp_created_date',
                                         'format'=>'raw',
                                          'filter'=>DatePicker::widget([
                                                  'model' =>$searchModel,
                                                      'attribute' => 'otp_created_date',
                                                  'clientOptions' => [
                                                      'autoclose' => true,
                                                      'format' => 'yyyy-m-d',
                                                  ]
                                              ]),
                                     ],

                                ],
                                'options' => [
                                    'changeMonth'=>true,
                                    'changeYear'=>true,
                                    'changeDay'=>false,
                                ]
                            ]);
                            ?>

I cant install this package it show error as

C:\wamp_new\www\yii2advance>php composer.phar require 2amigos/yii2-date-picker-w
idget:~1.0
You are running composer with xdebug enabled. This has a major impact on runtime
performance. See https://getcomposer.org/xdebug
The "yiisoft/yii2-composer" plugin requires composer-plugin-api 1.0.0, this WIL
L
break in the future and it should be fixed ASAP (require ^1.0 for example).
./composer.json has been updated
The "yiisoft/yii2-composer" plugin requires composer-plugin-api 1.0.0, this WIL
L
break in the future and it should be fixed ASAP (require ^1.0 for example).
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- 2amigos/yii2-date-picker-widget 1.0.x-dev requires bower-asset/bootstrap-d
atepicker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.5 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.4 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.3 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.2 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.1 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- 2amigos/yii2-date-picker-widget 1.0.0 requires bower-asset/bootstrap-datep
icker 1.4.0 -> no matching package found.
- Installation request for 2amigos/yii2-date-picker-widget ~1.0 -> satisfiab
le by 2amigos/yii2-date-picker-widget[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5,
1.0.x-dev].

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further commo
n problems.

Installation failed, reverting ./composer.json to its original content.

Html is broken in DateRangePicker

Not sure when exactly it happened - maybe after bootstrap updated to 3.3.4

See screen - seems that class form-control for container is excessive (after removing it input takes its place, but also input-group-addon height need to be adjusted):

qip shot - screen 612 31 03 15

After removing:

qip shot - screen 613 31 03 15

calendar not working when used with autocomplete

The following code results in the calendar always being displayed, and not working. There is no JS error in console.

<?php
use dosamigos\datepicker\DatePicker;
use yii\jui\AutoComplete;
?>
    <?php $form = ActiveForm::begin(['layout' => 'horizontal', 'enableClientValidation' => false]); ?>
            <?= $form->field($model, 'due')->widget(DatePicker::className(), [
                'clientOptions' => [
                    'autoclose' => true,
                    'format' => 'yyyy-mm-dd',
                ]
            ]) ?>
            <?= $form->field($model, 'country')->widget(AutoComplete::classname(), [
                'clientOptions' => [
                    'source' => ['USA', 'RUS'],
                ],
            ]) ?>
    <?php ActiveForm::end(); ?>

If the date is 0000-00-00

Hi, recently I using this plugin and I found that if the date is 0000-00-00 it cannot be search. how i can avoid this problem?
The data will 0000-00-00 and I know is bad habit for database but I really need this

Calendar does not pop up

When I click on the form field nothing happens. I can see the changes to the field, but doesn't work. Not sure if I missed something but I followed the installation without any issues.

<?php $form = ActiveForm::begin(); ?>

<?=$form->field($model, 'class_name')->dropDownList(
    ArrayHelper::map(ClassTitles::find()->all(), 'class_name','class_name'), ['prompt'=>'Select a Class'])?>

<?= $form->field($model, 'price')->textInput() ?>

<?= $form->field($model, 'weeks')->textInput() ?>

<?= $form->field($model, 'starting_date')->widget(
        DatePicker::className(), [
            // inline too, not bad
             'inline' => true, 
             // modify template for custom rendering
            'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'dd-M-yyyy'
            ]
    ]);?>

<?= $form->field($model, 'ending_date')->textInput() ?>

<?= $form->field($model, 'time')->textInput() ?>

<?= $form->field($model, 'duration')->textInput() ?>

<?= $form->field($model, 'scheduled_on')->textInput() ?>


<div class="form-group">
    <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

Localize

How I can use it with Yii::$app->language? If en_EN, ru_RU...

Does not work properly in dynamic forms

I don't know if should post this here or on dynamic form but I am posting anyway

I implemented it like this, the datepicker popup appears only for the first Item and not for the other dynamic items

خبرات العمل

    <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' => $WorkExperiencesModels[0],
            'formId' => 'dynamic-form',
            'formFields' => [
                'Title',
                'Description',
                'FKWorkSectorID',
                'FKCountryID',
                'FKCityID',
                'StartDate',
                'EndDate',
            ],
        ]); ?>


        <div class="container-items"><!-- widgetContainer -->
        <?php foreach ($WorkExperiencesModels as $i => $WorkExperiencesModel): ?>
            <div class="item panel panel-default"><!-- widgetBody -->
                <div class="panel-heading">
                    <h3 class="panel-title pull-left">خبرات العمل</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 (! $WorkExperiencesModel->isNewRecord) {
                            echo Html::activeHiddenInput($WorkExperiencesModel, "[{$i}]ID");
                        }
                    ?>
                    <?= $form->field($WorkExperiencesModel, "[{$i}]Title")->textInput(['maxlength' => true]) ?>
                    <div class="row">
                        <div class="col-sm-6">
                            <?= $form->field($WorkExperiencesModel, "[{$i}]Description")->textarea(['maxlength' => true]) ?>
                        </div>
                        <div class="col-sm-6">
                            <?= $form->field($WorkExperiencesModel, "[{$i}]FKWorkSectorID")->dropDownList(
                            ArrayHelper::map(Worksector::find()->all(), 'ID', 'Name'),           // Flat array ('id'=>'label')
                            ['prompt'=>'']    // options
                        ) ?>
                        </div>
                    </div><!-- .row -->
                    <div class="row">
                        <div class="col-sm-4">
                            <?= $form->field($WorkExperiencesModel, "[{$i}]FKCountryID")->dropDownList(
                                ArrayHelper::map(Countries::find()->all(), 'ID', 'Name'),           // Flat array ('id'=>'label')
                                ['prompt'=>'select country',    // options
                                  'onchange'=>'
                                                console.log("fired");
                                                $.post("index.php?r=cities/list&id='.'"+$(this).val(),function(data){
                                                    $("[{$i}]select#workexperience-fkcityid").html(data);
                                                });'
                                             ])
                            ?>
                        </div>
                        <div class="col-sm-4">
                            <?= $form->field($WorkExperiencesModel, "[{$i}]FKCityID")->dropDownList(
                                ArrayHelper::map(Cities::find()->all(), 'ID', 'Name'),           // Flat array ('id'=>'label')
                                ['prompt'=>'']    // options
                            )
                            ?>
                        </div>
                        <div class="col-sm-4">
                         <?= $form->field($WorkExperiencesModel, "[{$i}]StartDate")->widget(
                            DatePicker::className(), [
                                // inline too, not bad
                                 // 'inline' => true, 
                                 // modify template for custom rendering
                                'template' => '{addon}{input}',
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                    'startView'=>'year'
                                ]
                        ]);?>



                        </div>
                        <div class="col-sm-4">
                         <?= $form->field($WorkExperiencesModel, "[{$i}]EndDate")->widget(
                            DatePicker::className(), [
                                // inline too, not bad
                                 // 'inline' => true, 
                                 // modify template for custom rendering
                                'template' => '{addon}{input}',
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                    'startView'=>'year'
                                ]
                        ]);?>
                        </div>
                    </div><!-- .row -->
                </div>
            </div>
        <?php endforeach; ?>
        </div>
        <?php DynamicFormWidget::end(); ?>
    </div>
</div>

Multidate not working with 'inline'

When using multidate and multidateSeparator in inline mode I notice only the last date selected is being updated in the input tag.

<?= DatePicker::widget([
                'inline' => true,
                'name' => 'test',
                'template' => '<div class="well well-sm" 
style="background-color: #fff; width:250px">{input}</div>',
                'clientOptions' => [
                    'format' => "yyyy-mm-dd",
                    'weekStart' => 1,
                    'startDate' => "today+1",
                    'daysOfWeekDisabled' => "0",
                    'multidate' => true,
                    'multidateSeparator' => ";",
                ]
            ]);?>

For example if I select 2 dates :
The input tag value only contains 1 date ( last one selected ).

capture

dont take field value

this is my model :

<?php

namespace common\models;

use Yii;
use yii\validators;

/**
 * This is the model class for table "Eventi".
 *
 * @property integer $idEventi
 * @property string $nomeEvento
 * @property timestamp $datains
 * @property date $dataInizio
 * @property date $dataFine
 * @property date $dataPrevista
 * @property string $numPartecipanti
 * @property string $insegnante
 * @property string $svolgimento
 */
class Eventi extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    /*
    public $dataInizio;
    public $dataPrevista;
    public $dataFine;
    */
    public static function tableName()
    {
        return 'Eventi';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[ 'nomeEvento', 'svolgimento'], 'required'],
            [['svolgimento'], 'string'],
            [['nomeEvento', 'numPartecipanti', 'insegnante'], 'string', 'max' => 45],
            //[['dataInizio', 'dataFine', 'dataPrevista'],'controlloDate','skipOnEmpty' => false, 'skipOnError' => false]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'idEventi' => 'Id Eventi',
            'nomeEvento' => 'Nome Evento',
            'dataInizio' => 'Data Inizio',
            'dataFine' => 'Data Fine',
            'dataPrevista' => 'Data Prevista',
            'numPartecipanti' => 'Num Partecipanti',
            'insegnante' => 'Insegnante',
            'svolgimento' => 'Svolgimento',
        ];
    }

    public function controlloDate($attribute,$params){

        if (isset($this->dataPrevista)and !isset($this->dataInizio) and !isset($this->dataFine)){
            return true;

        }

        else {
            $this->addError($attribute, 'Se riempi il campo data prevista non puoi riempire i campi data fine e data inizio!');
            return false;
        }
    }
}

and this is my view

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datepicker\DatePicker;


/* @var $this yii\web\View */
/* @var $model common\models\Eventi */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="eventi-form">

    <?php $form = ActiveForm::begin(); ?>

    <?//S= $form->field($model, 'idEventi')->textInput() ?>

    <?= $form->field($model, 'nomeEvento')->textInput(['maxlength' => 45]) ?>
    <div class="col-lg-4">
        <?= $form->field($model, 'dataInizio')->widget(
            DatePicker::className(), [
            // inline too, not bad
            'inline' => false, 
            //lingua
            'language' => 'it',
            // modify template for custom rendering
            //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'yyyy-MM-dd'
            ]
        ]);?>
    </div>
    <div class="col-lg-4">
        <?= $form->field($model, 'dataFine')->widget(
            DatePicker::className(), [
            // inline too, not bad
            'inline' => false, 
             //lingua
            'language' => 'it',
            // modify template for custom rendering
            //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'yyyy-MM-dd'
            ]
        ]);?>
    </div>

    <div class="col-lg-4">
        <?= $form->field($model, 'dataPrevista')->widget(
            DatePicker::className(), [
            // inline too, not bad
            'inline' => false, 
             //lingua
            'language' => 'it',
            // modify template for custom rendering
            //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'yyyy-MM-dd'
            ]
        ]);?>
    </div>

    <?php 
        $t=time();
        $data=date("Y-m-d-G-i-s",$t);
    ?>
    <?= Html::activeHiddenInput($model,'data_ins',array('value'=>$data)) ?>

    <?= $form->field($model, 'numPartecipanti')->textInput(['maxlength' => 45]) ?>

    <?= $form->field($model, 'insegnante')->textInput(['maxlength' => 45]) ?>

    <?= $form->field($model, 'svolgimento')->textarea(['rows' => 6]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

but when i submit in the view i havent not value in thedate 3 fields

Multiple same form with DateRangePicker

Hello.

If i display same form multiple times at one page, DatePickerRange dosn`t appear more than 1 time (at first element).

Sample:
$form = ActiveForm::begin();
echo $form->field($model, 'date_attended_from')->widget(DateRangePicker::className(), [
'attributeTo' => 'date_attended_to',
'form' => $form,
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy-mm-dd'
]
]);
ActiveForm::end();

$form = ActiveForm::begin();
echo $form->field($model, 'date_attended_from')->widget(DateRangePicker::className(), [
'attributeTo' => 'date_attended_to',
'form' => $form,
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy-mm-dd'
]
]);
ActiveForm::end();

I think problem in duplicate id attribute. What can i do to fix that?

Installation Problem

I am trying to install this widget in mac machine. I went to my Yii2-advanced project folder in terminal and I ran this command

composer require 2amigos/yii2-date-picker-widget:~1.0

After that it gives me this error:-

Your requirements could not be resolved to an installable set of packages.

Problem 1

  • 2amigos/yii2-date-picker-widget 1.0.5 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • 2amigos/yii2-date-picker-widget 1.0.4 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • 2amigos/yii2-date-picker-widget 1.0.3 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • 2amigos/yii2-date-picker-widget 1.0.2 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • 2amigos/yii2-date-picker-widget 1.0.1 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • 2amigos/yii2-date-picker-widget 1.0.0 requires bower-asset/bootstrap-datepicker 1.4.0 -> no matching package found.
  • Installation request for 2amigos/yii2-date-picker-widget ~1.0 -> satisfiable by 2amigos/yii2-date-picker-widget[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5].

Side Note:- I don't have bootstrap-datepicker in my composer.json file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.