Jalali Date
Yii2 Jalali date & time library based on mohammad-mahdy/yii2-jdate., (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist elephantsgroup/eg-jdate "*"
or add, (*4)
"elephantsgroup/eg-jdate": "*"
to the require section of your composer.json
file., (*5)
Usage of DateTime
Once the extension is installed, add it as a component :, (*6)
'jdate' => [
'class' => 'elephantsGroup\jDate\DateTime'
]
Now you can use in your project:, (*7)
Yii::$app->jdate->date('Y-m-d');
You can access dates and times as variable :, (*8)
Yii::$app->jdate->Y;
Usage of DatePicker
It is a widget to make a input, box to giver jalali date from user., (*9)
A basic usage:, (*10)
<?= jDate\DatePicker::widget([
'name' => 'datepicker'
]) ?>
If you want set default date set value
:, (*11)
<?= jDate\DatePicker::widget([
'name' => 'datepicker', 'value' => '1394/01/01'
]) ?>
Using a model
:, (*12)
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date'
]) ?>
Use in active form
:, (*13)
<?= $form->field($model, 'fieldname')->widget(jDate\DatePicker::className()) ?>
Datepicker ClientOptions
Add these to ClientOptions
var., (*14)
Change date picker size:
[
'cellHeight' => 13,
'cellWidth' => 13
]
Change font size:
[
'fontSize' => 25
]
Use english numbers in date picker:
[
'persianNumbers' => false
]
[
'formatDate' => 'DD-NM-YYYY hh:m'
]
Datepicker Theme
Now date picker have 2 theme default
and dark
., (*15)
For set theme set theme
var., (*16)
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date', 'theme' => 'dark'
]) ?>
Datepicker Events
NOTE : If you want rewriting onSelect event and using active form
add options[id]
and add, (*17)
```javascript
$('#your id').trigger('change');, (*18)
>
> to your event function.
####`onHide` Event:
```php
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onHide' => 'function(){alert("Datepicker is now hidden!")}'
]
]) ?>
onSelect
Event:
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onSelect' => 'function(){alert("Date selected!")}'
]
]) ?>
onShow
Event:
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onShow' => 'function(){alert("Hello!")}'
]
]) ?>