/**
  * @inheritdoc
  */
 public function run()
 {
     $inputId = $this->options['id'];
     $hasModel = $this->hasModel();
     if (array_key_exists('value', $this->options)) {
         $value = $this->options['value'];
     } elseif ($hasModel) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     $options = array_merge($this->options, ['multiple' => true, 'value' => $value]);
     if ($hasModel) {
         $output = Html::activeListBox($this->model, $this->attribute, $this->items, $options);
     } else {
         $output = Html::listBox($this->name, $this->value, $this->items, $options);
     }
     $clientOptions = array_merge(['filter' => $this->filter, 'multiple' => $this->multiple, 'multipleWidth' => $this->multipleWidth], $this->clientOptions);
     if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
         $clientOptions['placeholder'] = $options['placeholder'];
     }
     $js = 'jQuery(\'#' . $inputId . '\').multipleSelect(' . Json::htmlEncode($clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         MultipleSelectAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
 public function renderSavedValueInput()
 {
     if ($this->hasModel()) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     if ($value !== null && $value !== '') {
         // format value according to saveDateFormat
         try {
             $value = Yii::$app->formatter->asDate($value, $this->saveDateFormat);
         } catch (InvalidParamException $e) {
             // ignore exception and keep original value if it is not a valid date
         }
     }
     $this->options['savedValueInputID'] = $this->options['id'] . '-saved-value';
     $options = $this->options;
     $options['id'] = $options['savedValueInputID'];
     $options['value'] = $value;
     // render hidden input
     if ($this->hasModel()) {
         $contents = Html::activeHiddenInput($this->model, $this->attribute, $options);
     } else {
         $contents = Html::hiddenInput($this->name, $value, $options);
     }
     return $contents;
 }
Esempio n. 3
1
 /**
  * @inheritdoc
  */
 public function run()
 {
     try {
         $this->_initAndValidate();
         $valueArray = [];
         $trees = [];
         $valueSingle = "";
         $select = "";
         $singleInput = "";
         if (in_array($this->mode, [self::MOD_COMBO, self::MOD_MULTI])) {
             $valueArray = Html::getAttributeValue($this->model, $this->attribute);
             $select = Html::activeListBox($this->model, $this->attribute, ['16' => "16"], ['multiple' => true, 'class' => 'sx-controll-element', 'style' => 'display: none;']);
             $trees = Tree::find()->where(['id' => $valueArray])->all();
         }
         if (in_array($this->mode, [self::MOD_COMBO, self::MOD_SINGLE])) {
             $singleInput = Html::activeInput("hidden", $this->model, $this->attributeSingle, ['class' => 'sx-single']);
             $valueSingle = Html::getAttributeValue($this->model, $this->attributeSingle);
         }
         $src = UrlHelper::construct('/cms/admin-tree')->set('mode', $this->mode)->set('s', $valueArray)->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
         $id = "sx-id-" . md5(serialize([$this->clientOptions, $this->mode, $this->attributeMulti, $this->attributeSingle]));
         $selected = [];
         foreach ($trees as $tree) {
             $selected[] = $tree->id;
         }
         return $this->render('widget', ['widget' => $this, 'id' => $id, 'select' => $select, 'src' => $src, 'valueSingle' => $valueSingle, 'singleInput' => $singleInput, 'clientOptions' => Json::encode(['src' => $src, 'name' => $id, 'id' => $id, 'selected' => $selected, 'valueSingle' => $valueSingle])]);
         //$this->registerClientScript();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 4
1
 /**
  * @inheritdoc
  */
 public function run()
 {
     $this->_msgCat = 'kvcolor';
     if (!isset($this->type)) {
         $this->type = $this->useNative ? 'color' : 'text';
     }
     $this->width = '60px';
     $this->initI18N(__DIR__);
     if (empty($this->html5Container['id'])) {
         $this->html5Container['id'] = $this->options['id'] . '-cont';
     }
     if ($this->type === 'text') {
         Html::addCssStyle($this->html5Options, 'display:none');
         if ($this->pluginLoading) {
             Html::addCssClass($this->html5Container, 'kv-center-loading');
         }
     }
     $this->html5Options['value'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     if (substr($this->language, 0, 2) !== 'en') {
         $this->_defaultOptions += ['cancelText' => Yii::t('kvcolor', 'cancel'), 'chooseText' => Yii::t('kvcolor', 'choose'), 'clearText' => Yii::t('kvcolor', 'Clear Color Selection'), 'noColorSelectedText' => Yii::t('kvcolor', 'No Color Selected'), 'togglePaletteMoreText' => Yii::t('kvcolor', 'more'), 'togglePaletteLessText' => Yii::t('kvcolor', 'less')];
     }
     Html::addCssClass($this->containerOptions, 'spectrum-group');
     Html::addCssClass($this->html5Options, 'spectrum-source');
     Html::addCssClass($this->options, 'spectrum-input');
     if (!$this->useNative) {
         Html::addCssClass($this->html5Container, 'input-group-sp');
         $this->pluginOptions = array_replace_recursive($this->_defaultOptions, $this->pluginOptions);
     }
     $this->initInput();
     $this->registerColorInput();
 }
Esempio n. 5
1
 /**
  * Initializes the widget.
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     foreach ($this->items as $value => $item) {
         if (is_string($item)) {
             throw new InvalidConfigException("Items cannot be of type string.");
         }
         $item['options'] = ['value' => $value];
     }
     if ($this->hasModel()) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
         if (!empty($value)) {
             $defaultText = $value;
         }
     } else {
         if (!empty($this->value)) {
             $defaultText = $this->value;
         }
     }
     if (empty($defaultText)) {
         $defaultText = Yii::t('dosamigos/semantic/selection', 'Select...');
     }
     $this->defaultText = $this->encodeDefaultText ? Html::encode($defaultText) : $defaultText;
     Html::addCssClass($this->options, 'selection');
 }
Esempio n. 6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $this->clientOptions = array_merge_recursive(self::$defaultSettings, $this->clientOptions);
     $this->clientOptions['extended_valid_elements'] = implode(',', $this->clientOptions['extended_valid_elements']);
     if ($this->hasModel()) {
         $this->options['name'] = isset($this->options['name']) ? $this->options['name'] : Html::getInputName($this->model, $this->attribute);
         if (isset($this->options['value'])) {
             $value = $this->options['value'];
             unset($this->options['value']);
         } else {
             $value = Html::getAttributeValue($this->model, $this->attribute);
         }
         if (!array_key_exists('id', $this->options)) {
             $this->options['id'] = Html::getInputId($this->model, $this->attribute);
         }
     } else {
         $options['name'] = $this->name;
         $value = $this->value;
     }
     if (!isset($this->options['class'])) {
         $this->options['class'] = 'tinymce';
     }
     echo Html::tag('div', $value, $this->options);
     $this->registerClientScript();
 }
 /**
  * @param $column
  * @return void
  */
 public function composeFilterState($column)
 {
     if (!preg_match('/(^|.*\\])([\\w\\.]+)(\\[.*|$)/', $column->attribute, $matches)) {
         throw new InvalidParamException('Attribute name must contain word characters only.');
     }
     $formName = $this->_gridView->filterModel->formName();
     $value = Html::getAttributeValue($this->_gridView->filterModel, $column->attribute);
     $keys = [$formName];
     if ($matches[1] === '') {
         $keys[] = $matches[2];
         if ($matches[3] !== '') {
             $keys[] = $matches[3];
         }
     } else {
         $keys[] = $matches[1];
         $keys[] = $matches[2];
         if ($matches[3] !== '') {
             $keys[] = $matches[3];
         }
     }
     $s =& $this->_state;
     foreach ($keys as $key) {
         if (end($keys) === $key) {
             is_array($s) and $s[$key] = $value;
         } else {
             $s[$key] = isset($s[$key]) ? $s[$key] : [];
             $s =& $s[$key];
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     $inputId = $this->options['id'];
     $hasModel = $this->hasModel();
     if (array_key_exists('value', $this->options)) {
         $value = $this->options['value'];
     } elseif ($hasModel) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     $options = array_merge($this->options, ['value' => $value]);
     if ($hasModel) {
         $output = Html::activeTextInput($this->model, $this->attribute, $options);
     } else {
         $output = Html::textInput($this->name, $this->value, $options);
     }
     if (!is_null($this->alias)) {
         $clientOptions = array_merge($this->clientOptions, ['alias' => $this->alias]);
     } else {
         $clientOptions = array_merge($this->clientOptions, ['mask' => $this->mask]);
     }
     if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
         $clientOptions['placeholder'] = $options['placeholder'];
     }
     $js = 'jQuery(\'#' . $inputId . '\').inputmask(' . Json::htmlEncode($clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         InputMaskAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
Esempio n. 9
0
 public function init()
 {
     parent::init();
     $this->_inputStr = '<div class="form-group">';
     if ($this->hasModel()) {
         $this->_inputStr .= Html::activeLabel($this->model, $this->attribute);
     } else {
         $this->_inputStr .= Html::label($this->name);
     }
     $this->_inputStr .= '<div id="' . Html::encode($this->name) . '" class="input-group date">';
     if ($this->hasModel()) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     if ($value !== null) {
         $value = Yii::$app->formatter->asDatetime($value);
     }
     $options = $this->options;
     $options['class'] = 'form-control';
     //$options['readonly'] = '';
     $options['value'] = $value;
     if ($this->hasModel()) {
         $this->_inputStr .= Html::activeTextInput($this->model, $this->attribute, $options);
     } else {
         $this->_inputStr .= Html::textInput($this->name, $this->value, $options);
     }
     $this->_inputStr .= '<span class="input-group-addon">
                                     <span class="glyphicon-calendar glyphicon"></span>
                                 </span>
                             </div>
                             </div>
                             ';
 }
Esempio n. 10
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded', [], 'en'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed', [], 'en'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large', [], 'en'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small', [], 'en')]], $this->clientOptions);
 }
Esempio n. 11
0
 public function run()
 {
     if (!$this->hasModel() || !$this->attribute) {
         throw new InvalidConfigException('Fuzzydate DatePicker must have model and attribute.');
     }
     $view = $this->getView();
     $asset = new DatePickerAsset();
     $asset->register($view);
     $view->registerJs("fuzzyReg();");
     $id = Html::getInputId($this->model, $this->attribute);
     $val = Html::getAttributeValue($this->model, $this->attribute);
     if ($val && is_array($val)) {
         $y = $val['y'];
         if ($y) {
             $m = $val['m'];
             if (!$m) {
                 $m = 'null';
             }
             $d = $val['d'];
             if (!$d) {
                 $d = 'null';
             }
             // Call this after initializing jQuery-objects
             $view->registerJs("fuzzySet('{$id}', {$y}, {$m}, {$d});", View::POS_LOAD);
         }
     }
     if (!$this->minYear) {
         $this->minYear = date('Y');
     }
     if (!$this->maxYear) {
         $this->maxYear = date('Y');
     }
     $widget = $this->getViewPath() . DIRECTORY_SEPARATOR . 'datePicker.php';
     echo $view->renderFile($widget, ['widget' => $this]);
 }
Esempio n. 12
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1 || $this->multiple) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     if ($this->files) {
         foreach ($this->files as &$file) {
             if (!isset($file['alias_url']) && is_array($file)) {
                 $option = isset($this->clientOptions['baseUrlAttribute']) ? $this->clientOptions['baseUrlAttribute'] : null;
                 $file['alias_url'] = $option ? isset($file[$option]) ? Yii::getAlias($file[$option]) : null : null;
             }
         }
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'showPreviewFilename' => $this->showPreviewFilename, 'pathAttribute' => 'path', 'baseUrlAttribute' => 'base_url', 'pathAttributeName' => 'path', 'baseUrlAttributeName' => 'base_url', 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small')]], $this->clientOptions);
 }
Esempio n. 13
0
 public function run()
 {
     call_user_func([$this, 'register' . ucfirst($this->driver) . 'ClientJs']);
     $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     // 已经传过图片,显示预览图
     $image = $value ? Html::img(strpos($value, 'http:') === false ? \Yii::getAlias('@static') . '/' . $value : $value, ['width' => $this->options['previewWidth'], 'height' => $this->options['previewHeight']]) : '';
     return $this->render('main', ['boxId' => $this->options['boxId'], 'hiddenInput' => $this->hiddenInput, 'image' => $image]);
 }
Esempio n. 14
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $web = rtrim(\Yii::getAlias('@static'), '/');
     $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $image = $value ? Html::img(strpos($value, 'http:') === false ? \Yii::getAlias('@static') . '/' . $value : $value, ['width' => $this->options['previewWidth'], 'height' => $this->options['previewHeight']]) : '';
     $this->registerClientScript();
     return $this->render('cropper', ['options' => $this->options, 'image' => $image, 'server' => $this->server, 'hiddenInput' => $this->hiddenInput, 'web' => $web]);
 }
Esempio n. 15
0
 public function run()
 {
     $this->tagOptions['data-input'] = '#' . $this->options['id'];
     $this->options['style'] = 'display: none;';
     $this->registerClientScripts();
     echo Html::tag('div', Html::getAttributeValue($this->model, $this->attribute), $this->tagOptions);
     echo Html::activeTextarea($this->model, $this->attribute, $this->options);
 }
Esempio n. 16
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     echo Html::tag('div', '', $this->options);
     $this->registerClientScript();
 }
Esempio n. 17
0
 /**
  * Configure client options
  *
  * @return void
  */
 protected function configureClientOptions()
 {
     $assetBundle = StarRatingAsset::register($this->view);
     $this->clientOptions['score'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $this->clientOptions['path'] = $assetBundle->baseUrl . self::IMAGE_PATH;
     if (!isset($this->clientOptions['scoreName']) && $this->hasModel()) {
         $this->clientOptions['scoreName'] = Html::getInputName($this->model, $this->attribute);
     }
 }
Esempio n. 18
0
 public function reayOnly($value = null, $options = [])
 {
     $options = array_merge($this->inputOptions, $options);
     $this->adjustLabelFor($options);
     $value = $value === null ? Html::getAttributeValue($this->model, $this->attribute) : $value;
     $options['class'] = 'da-style';
     $options['style'] = 'display: inline-block;';
     $this->parts['{input}'] = Html::activeHiddenInput($this->model, $this->attribute) . Html::tag('span', $value, $options);
     return $this;
 }
Esempio n. 19
0
 public function run()
 {
     $this->registerClientJs();
     $value = Html::getAttributeValue($this->model, $this->attribute);
     $content = $value ? Html::img(strpos($value, 'http:') === false ? \Yii::getAlias('@static') . '/' . $value : $value, ['width' => $this->options['previewWidth'], 'height' => $this->options['previewHeight']]) : $this->options['innerHTML'];
     if ($this->hasModel()) {
         return Html::tag('div', $content, ['id' => $this->options['boxId']]) . Html::activeHiddenInput($this->model, $this->attribute);
     } else {
         return Html::tag('div', $content, ['id' => $this->options['boxId']]) . Html::hiddenInput($this->name, $this->value);
     }
 }
Esempio n. 20
0
 public function init()
 {
     parent::init();
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     $this->config["model"] = $this->model;
     $this->config['attribute'] = $this->attribute;
     $this->config['view'] = $this->getView();
 }
Esempio n. 21
0
 public function run()
 {
     $this->registerClientScript();
     if ($this->hasModel()) {
         $inputName = Html::getInputName($this->model, $this->attribute);
         $inputValue = Html::getAttributeValue($this->model, $this->attribute);
         return $this->render('index', ['config' => $this->config, 'inputName' => $inputName, 'inputValue' => $inputValue]);
     } else {
         return $this->render('index', ['config' => $this->config, 'inputName' => 'file-upload', 'inputValue' => $this->value]);
     }
 }
Esempio n. 22
0
 public function getButtonClass($value)
 {
     $selectedValue = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $state = $this->comparisonStrict || ($selectedValue === null || $selectedValue === '') && $this->ignoreEmpty ? $value === $selectedValue : $value == $selectedValue ? self::STATE_ACTIVE : self::STATE_DEFAULT;
     $buttonOptions = isset($this->itemOptions['buttons'][$value]) ? $this->itemOptions['buttons'][$value] : null;
     if ($buttonOptions && isset($buttonOptions[$state])) {
         $class = $buttonOptions[$state];
     } else {
         $class = $this->itemOptions[$state];
     }
     return $class;
 }
Esempio n. 23
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     $categories = Html::getAttributeValue($this->model, $this->attribute);
     $model = new Category();
     $tree = Category::findOne(['module' => $this->model->moduleName, $model->leftAttribute => 1]);
     if ($tree) {
         $tree = $tree->buildTreeHtml([], [], ['actions' => '<div class="btn-group pull-right">
                 <input type="checkbox" {check} class="choseCategories" name="choseCategories[]" value="{_id}">
             </div>'], $categories);
     }
     echo $tree;
 }
Esempio n. 24
0
 public function run()
 {
     // 获取字段的值
     $attributeValue = Html::getAttributeValue($this->model, $this->attribute);
     /*$attributeValue = [
           'image/image.png',
           'image/image.png',
           'image/image.png',
           'image/image.png',
           'image/image.png',
       ];*/
     return $this->render('index', ['title' => $this->title, 'attribute' => $this->attribute, 'attributeValue' => $attributeValue]);
 }
Esempio n. 25
0
 private function setNameAndValue()
 {
     if ($this->model) {
         $this->_name = Html::getInputName($this->model, $this->attribute);
         $this->_value = Html::getAttributeValue($this->model, $this->attribute);
         if (!array_key_exists('id', $this->options)) {
             $this->options['id'] = Html::getInputId($this->model, $this->attribute);
         }
     } else {
         $this->_name = $this->attribute;
         $this->_value = $this->value;
     }
 }
Esempio n. 26
0
 public function run()
 {
     $this->normalizeMaxLength();
     $this->registerClientScript();
     $input = $this->renderInput();
     if (!isset($this->options['maxlength'])) {
         return $input;
     }
     $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $taken = mb_strlen($value, 'UTF-8');
     $left = $this->options['maxlength'] - $taken;
     return '<div class="input-group" data-field="count-characters">' . $input . '<span class="input-group-addon" data-field="characters-remaining">' . $left . '</span></div>';
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->options = ArrayHelper::merge($this->asDataAttributes($this->clientOptions), $this->options);
     $this->clientOptions = false;
     if ($this->hasModel()) {
         $this->options['data-name'] = Html::getInputName($this->model, $this->attribute);
         $this->options['data-value'] = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $this->options['data-name'] = $this->name;
         $this->options['data-value'] = $this->value;
     }
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     $hasModel = $this->hasModel();
     if ($hasModel) {
         if (array_key_exists('value', $this->options)) {
             $value = $this->options['value'];
         } else {
             $value = Html::getAttributeValue($this->model, $this->attribute);
         }
     } else {
         $value = $this->value;
     }
     $altValue = $value;
     if ($hasModel) {
         $this->options = array_merge($this->options, ['name' => false, 'value' => $value]);
         $this->altOptions['value'] = $altValue;
         $output = Html::activeTextInput($this->model, $this->attribute, $this->options) . Html::activeHiddenInput($this->model, $this->attribute, $this->altOptions);
     } else {
         $output = Html::textInput(false, $value, $this->options) . Html::hiddenInput($this->name, $altValue, $this->altOptions);
     }
     $js = 'jQuery(\'#' . $this->options['id'] . '\').inputmask(' . Json::htmlEncode($this->clientOptions) . ').keyup(function (event) { jQuery(\'#' . $this->altOptions['id'] . '\').val(jQuery(this).inputmask(\'unmaskedvalue\')); });';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         InputMaskAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
Esempio n. 29
-1
 public function init()
 {
     if ($this->name === null && !$this->hasModel() && $this->selector === null) {
         throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
     }
     if (null === $this->schema) {
         throw new InvalidConfigException("You must specify 'schema' property.");
     }
     if ($this->hasModel() && !isset($this->options['id'])) {
         $this->options['id'] = Html::getInputId($this->model, $this->attribute);
     }
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!isset($this->containerOptions['id'])) {
         $this->containerOptions['id'] = ($this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId()) . '-container';
     }
     if ($this->inputId === null) {
         $this->inputId = $this->options['id'];
     } else {
         $this->_renderInput = false;
     }
     parent::init();
     JsonEditorAsset::register($this->getView());
 }
 protected function renderWidget()
 {
     $contents = [];
     // get formatted date value
     if ($this->hasModel()) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     $options = $this->options;
     $options['value'] = $value;
     if ($this->inline === false) {
         // render a text input
         if ($this->hasModel()) {
             $contents[] = Html::activeTextInput($this->model, $this->attribute, $options);
         } else {
             $contents[] = Html::textInput($this->name, $value, $options);
         }
     } else {
         // render an inline date picker with hidden input
         if ($this->hasModel()) {
             $contents[] = Html::activeHiddenInput($this->model, $this->attribute, $options);
         } else {
             $contents[] = Html::hiddenInput($this->name, $value, $options);
         }
         $this->clientOptions['defaultDate'] = $value;
         $this->clientOptions['altField'] = '#' . $this->options['id'];
         $contents[] = Html::tag('div', null, $this->containerOptions);
     }
     return implode("\n", $contents);
 }