Skip to content

Commit

Permalink
Merge pull request #124 from krissss/master
Browse files Browse the repository at this point in the history
Support the use of name, value for widget
  • Loading branch information
Eugene Terentev authored Feb 3, 2018
2 parents 7aff86e + 5f14505 commit 31d4ff5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ echo \trntv\filekit\widget\Upload::widget([
]);
```

Standalone usage - without model
```php
echo \trntv\filekit\widget\Upload::widget([
'name' => 'filename',
'hiddenInputId' => 'filename', // must for not use model
'url' => ['upload'],
'sortable' => true,
'maxFileSize' => 10 * 1024 * 1024, // 10Mb
'minFileSize' => 1 * 1024 * 1024, // 1Mb
'maxNumberOfFiles' => 3 // default 1,
'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'),
'showPreviewFilename' => false,
'clientOptions' => [ ...other blueimp options... ]
]);
```

With ActiveForm
```php
echo $form->field($model, 'files')->widget(
Expand Down
8 changes: 7 additions & 1 deletion src/widget/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class Upload extends InputWidget
* @var bool preview image file or not in the upload box.
*/
public $previewImage = true;
/**
* custom hiddenInput id,if not set $this->options['id'] will be use.
* useful if use name,value
* @var null|string
*/
public $hiddenInputId = null;

/**
* @throws \yii\base\InvalidConfigException
Expand Down Expand Up @@ -159,7 +165,7 @@ public function run()
$content = Html::beginTag('div');
$content .= Html::hiddenInput($this->name, null, [
'class' => 'empty-value',
'id' => $this->options['id']
'id' => $this->hiddenInputId === null ? $this->options['id'] : $this->hiddenInputId
]);
$content .= Html::fileInput($this->getFileInputName(), null, [
'name' => $this->getFileInputName(),
Expand Down

0 comments on commit 31d4ff5

Please sign in to comment.