Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\widgets;
- use app\assets\DropdownDatePickerAsset;
- use app\models\plugins\DropdownDatePicker;
- use yii\widgets\InputWidget;
- use yii\helpers\Html;
- use yii\helpers\Json;
- class DateDropdownInput extends InputWidget
- {
- public $defaultDate;
- public $minDate = '1921-01-01';
- public $maxDate = '';
- public $pluginName = 'dropdownDatepicker';
- protected $pluginOptions;
- public function __construct(DropdownDatePicker $pluginOptions, $config = [])
- {
- $this->pluginOptions = $pluginOptions;
- if (!empty($config)) {
- \Yii::configure($this, $config);
- }
- $this->init();
- }
- public function init()
- {
- DropdownDatePickerAsset::register($this->view);
- parent::init();
- $pluginOptions = $this->pluginOptions;
- foreach ($pluginOptions->attributes() as $attribute) {
- if ($this->hasProperty($attribute) && !empty($this->{$attribute})) {
- $pluginOptions->{$attribute} = $this->{$attribute};
- }
- }
- }
- public function run(): Void
- {
- $view = $this->view;
- $language = Json::htmlEncode(\Yii::$app->language);
- $pluginName = $this->pluginName;
- $pluginOptons = Json::htmlEncode($this->pluginOptions);
- $inputId = $this->options['id'];
- echo Html::activehiddenInput($this->model, $this->attribute);
- $js = <<<JS
- (function($) {
- const localeData = moment.localeData($language);
- $('#{$inputId}').{$pluginName}(${pluginOptons});
- })(jQuery);
- JS;
- $view->registerJs($js);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement