fileInput() public method

This method will generate the name and value tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public fileInput ( array $options = [] )
$options array the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
コード例 #1
0
 /**
  * @inheritdoc
  */
 public function fileInput($options = [])
 {
     $options = array_merge($this->inputOptions, $options);
     $options['wrapperOptions']['tag'] = isset($options['wrapperOptions']) && isset($options['wrapperOptions']['tag']) ? $options['wrapperOptions']['tag'] : 'div';
     $this->_setWrapperOptions($options, 'input input-file');
     // Set template
     $this->template = $this->fileInputTemplate;
     // Button
     $btnOptions = ArrayHelper::remove($options, 'buttonOptions', []);
     $btnTag = ArrayHelper::remove($btnOptions, 'tag', 'span');
     $btnContent = ArrayHelper::remove($btnOptions, 'content', 'Browse');
     Html::addCssClass($btnOptions, 'button');
     $this->parts['{beginButton}'] = Html::beginTag($btnTag, $btnOptions);
     $this->parts['{contentButton}'] = $btnContent;
     $this->parts['{endButton}'] = Html::endTag($btnTag);
     // Placeholder input
     $phrOptions = ArrayHelper::remove($options, 'placeholderOptions', []);
     $phrOptions['readonly'] = 'readonly';
     $placeholder = ArrayHelper::remove($options, 'placeholder');
     if ($placeholder !== null) {
         $phrOptions['placeholder'] = $placeholder;
     }
     $this->parts['{placeholder}'] = Html::input('text', null, null, $phrOptions);
     // Onchange
     $onchange = 'this.parentNode.nextSibling.value = this.value';
     $options['onchange'] = isset($options['onchange']) ? $options['onchange'] : $onchange;
     return parent::fileInput($options);
 }
コード例 #2
0
ファイル: ActiveField.php プロジェクト: creators/yii2-metroui
 public function fileInput($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             $this->template = $this->fileTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         $this->labelOptions['class'] = null;
     }
     $this->options['class'] = str_replace('text', 'file', $this->options['class']);
     return parent::fileInput($options, $enclosedByLabel);
 }
コード例 #3
0
ファイル: ActiveField.php プロジェクト: cookyii/base
 /**
  * @inheritdoc
  */
 public function fileInput($options = [])
 {
     Html::addCssClass($this->options, 'form-group--file-input');
     $options = array_merge($this->inputOptions, $options);
     $options['title'] = $this->model->getAttributeLabel($this->attribute);
     $options['ng-model'] = ArrayHelper::remove($options, 'ng-model', sprintf('data.%s', $this->attribute));
     $this->beforeRenderInput(__METHOD__, $options);
     return parent::fileInput($options);
 }