mjm / jdate
Jalali date & time.
Installs: 214
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 13
Language:JavaScript
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-11-13 20:57:01 UTC
README
Jalali date & time is an extension for yii2.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mjm/jdate "*"
or add
"mjm/jdate": "*"
to the require section of your composer.json
file.
Usage of DateTime
Once the extension is installed, add it as a component :
'jdate' => [ 'class' => 'mjm\jdate\DateTime' ]
Now you can use in your project:
Yii::$app->jdate->date('Y-m-d');
You can access dates and times as variable :
Yii::$app->jdate->Y;
Usage of DatePicker
It is a widget to make a input, box to giver jalali date from user.
A basic usage:
<?= mjm\jdate\DatePicker::widget([ 'name' => 'datepicker' ]) ?>
If you want set default date set value
:
<?= mjm\jdate\DatePicker::widget([ 'name' => 'datepicker', 'value' => '1394/01/01' ]) ?>
Using a model
:
<?= mjm\jdate\DatePicker::widget([ 'model' => $model, 'attribute' => 'date' ]) ?>
Use in active form
:
<?= $form->field($model, 'fieldname')->widget(mjm\jdate\DatePicker::className()) ?>
###Datepicker ClientOptions
###
Add these to
ClientOptions
var.
####Change date picker size:
[ 'cellHeight' => 13, 'cellWidth' => 13 ]
####Change font size:
[ 'fontSize' => 25 ]
####Use english numbers in date picker:
[ 'persianNumbers' => false ]
####Date format:
[ 'formatDate' => 'DD-NM-YYYY hh:m' ]
###Datepicker Theme
###
Now date picker have 2 theme default
and dark
.
For set theme set theme
var.
<?= mjm\jdate\DatePicker::widget([ 'model' => $model, 'attribute' => 'date', 'theme' => 'dark' ]) ?>
###Datepicker Events
#####
NOTE : If you want rewriting onSelect event and using
active form
addoptions[id]
and add
$('#your id').trigger('change');
>
> to your event function.
####`onHide` Event:
```php
<?= mjm\jdate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onHide' => 'function(){alert("Datepicker is now hidden!")}'
]
]) ?>
####onSelect
Event:
<?= mjm\jdate\DatePicker::widget([ 'model' => $model, 'attribute' => 'date', 'ClientOptions' => [ 'onSelect' => 'function(){alert("Date selected!")}' ] ]) ?>
####onShow
Event:
<?= mjm\jdate\DatePicker::widget([ 'model' => $model, 'attribute' => 'date', 'ClientOptions' => [ 'onShow' => 'function(){alert("Hello!")}' ] ]) ?>