/**
  * @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;
 }
예제 #2
-1
 /**
  * @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;
 }