/**
  * Registers the needed client assets
  *
  * @return void
  */
 public function registerAssets()
 {
     if ($this->disabled) {
         return;
     }
     $view = $this->getView();
     if (!empty($this->_langFile)) {
         DatePickerAsset::register($view)->js[] = $this->_langFile;
     } else {
         DatePickerAsset::register($view);
     }
     $id = "jQuery('#" . $this->options['id'] . "')";
     $el = "jQuery('#" . $this->options['data-datepicker-source'] . "')";
     $this->registerPlugin($this->pluginName, $el);
     if ($this->type === self::TYPE_INLINE) {
         $view->registerJs("{$el}.on('changeDate',function(e){{$id}.val(e.format()).trigger('change')});");
     }
     if ($this->_hasAddon && $this->removeButton !== false) {
         $view->registerJs("initDPRemove('" . $this->options['id'] . "');");
     }
     if ($this->_hasAddon) {
         $view->registerJs("initDPAddon('" . $this->options['id'] . "');");
     }
     if ($this->type === self::TYPE_RANGE) {
         \kartik\field\FieldRangeAsset::register($view);
         $view->registerJs("initDPRemove('" . $this->options['id'] . "', true);");
     }
 }
Example #2
0
 /**
  * Registers the needed client assets
  */
 public function registerAssets()
 {
     if ($this->disabled) {
         return;
     }
     $view = $this->getView();
     if (!empty($this->_langFile)) {
         DatePickerAsset::register($view)->js[] = $this->_langFile;
     } else {
         DatePickerAsset::register($view);
     }
     $id = "jQuery('#" . $this->options['id'] . "')";
     if ($this->type == self::TYPE_INLINE) {
         $this->pluginEvents = ArrayHelper::merge($this->pluginEvents, ['changeDate' => 'function (e) { ' . $id . '.val(e.format());} ']);
     }
     if ($this->type === self::TYPE_INPUT) {
         $this->registerPlugin('datepicker');
     } elseif ($this->type === self::TYPE_RANGE && isset($this->form)) {
         $this->registerPlugin('datepicker', "{$id}.parent().parent()");
     } else {
         $this->registerPlugin('datepicker', "{$id}.parent()");
     }
     if ($this->type === self::TYPE_RANGE) {
         \kartik\field\FieldRangeAsset::register($view);
     }
 }
Example #3
0
 /**
  * Registers the needed client assets
  */
 public function registerAssets()
 {
     if ($this->disabled) {
         return;
     }
     $view = $this->getView();
     if (!empty($this->_langFile)) {
         DatePickerAsset::register($view)->js[] = $this->_langFile;
     } else {
         DatePickerAsset::register($view);
     }
     $id = "jQuery('#" . $this->options['id'] . "')";
     $this->options['data-datepicker-type'] = $this->type;
     if ($this->type == self::TYPE_INLINE) {
         $this->pluginEvents = ArrayHelper::merge($this->pluginEvents, ['changeDate' => 'function (e) { ' . $id . '.val(e.format());} ']);
     }
     if ($this->type === self::TYPE_INPUT) {
         $this->registerPlugin('datepicker');
     } elseif ($this->type === self::TYPE_RANGE && isset($this->form)) {
         $this->registerPlugin('datepicker', "{$id}.parent().parent()");
     } else {
         $this->registerPlugin('datepicker', "{$id}.parent()");
     }
     if ($this->removeButton !== false && $this->_hasAddon) {
         $view->registerJs("{$id}.parent().find('.kv-date-remove').on('click', function() {\n                {$id}.parent().datepicker('clearDates');\n            });");
     }
     if ($this->type === self::TYPE_RANGE) {
         \kartik\field\FieldRangeAsset::register($view);
     }
 }
Example #4
0
 /**
  * Registers client assets
  */
 protected function registerAssets()
 {
     $view = $this->getView();
     $name = 'kvFieldRange';
     FieldRangeAsset::register($view);
     $id = '$("#' . $this->options2['id'] . '")';
     $options = Json::encode([
         'attrFrom' => $this->options1['id'],
         'container' => $this->container['id'],
         'errorContainer' => $this->errorContainer['id'],
     ]);
     $hashVar = $name . '_' . hash('crc32', $options);
     $this->options['data-krajee-'.$name] = $hashVar;
     $view->registerJs("var {$hashVar} = {$options};\n", View::POS_HEAD);
     $view->registerJs("{$id}.{$name}({$hashVar});");
 }