S
S
skajtersen2017-06-01 09:05:46
Yii
skajtersen, 2017-06-01 09:05:46

How to bind values ​​from DateRangePicker to model variables?

Available model

class PlotCreation extends \yii\base\Model
{

    public $date_from;
    public $date_to;
...
}

The view has a kartik\daterange\DateRangePicker widget
echo DateRangePicker::widget([
        'name' => 'date_range',
        'value' => '2017-05-02 01:00:00 PM - 2017-05-03 01:00:00 PM',
        'convertFormat' => true,
        'pluginOptions' => [
            'timePicker' => true,
            'timePickerIncrement' => 10,
            'locale' => ['format' => 'Y-m-d h:i:s']
        ]
    ]);

Please tell me how to write something in the controller to bind the selected end and start values ​​to the $date_to and $date_from variables.
And is it possible to add a timezone selection in the widget itself?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
B_bird, 2017-06-01
@skajtersen

The documentation says:

startAttribute : string, the attribute name which you can set optionally to track changes to the range start value. One of the following actions will be taken when this is set:
If using with model, an active hidden input will be automatically generated using this as an attribute name for the start value of the range.
endAttribute : string, the attribute name which you can set optionally to track changes to the range end value. One of the following actions will be taken when this is set:
If using with model, an active hidden input will be automatically generated using this as an attribute name for the end value of the range.

M
Maxim Timofeev, 2017-06-01
@webinar

Example from the docs :

$model->datetime_start = '2016-02-11';
$model->datetime_end = '2016-03-15';
echo '<div class="input-group drp-container">';
echo DateRangePicker::widget([
    'model'=>$model,
    'attribute' => 'kvdate1',
    'useWithAddon'=>true,
    'convertFormat'=>true,
    'startAttribute' => 'datetime_start',
    'endAttribute' => 'datetime_end',
    'pluginOptions'=>[
        'locale'=>['format' => 'Y-m-d'],
    ]
]) . $addon;
echo '</div>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question