Страница 1 из 1
dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.13, 17:52
yura1976
Использую для мультизагрузки файлов dosamigos FileUploadUI. По умолчанию отображаются кнопки "Добавить файлы", "Начать загрузку", "Отменить загрузку" и "Удалить". Что нужно сделать, чтобы оставить только одну кнопку "Добавить файлы", а остальные удалить?
В представлении код:
Код: Выделить всё
echo FileUploadUI::widget([
'model' => $model,
'attribute' => 'filename',
'url' => ['/catalog/articles/file-upload'],
'fieldOptions' => [
'multiple' => true,
],
'clientOptions' => [
'maxFileSize' => 2000000
]
]);
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.13, 18:21
yiiliveext
Вы можете использовать свою вьюху, пределав
https://github.com/2amigos/yii2-file-up ... upload.php
Код: Выделить всё
'uploadTemplateView' => '@app/views/my-upload-view'
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 11:47
yura1976
Спасибо! Отобразилось то что нужно. Но при нажатии на кнопку "Добавить файлы" ничего не происходит. В консоли сразу после загрузки страницы с формой (еще даже при ненажатой кнопке "Добавить файлы"):
Код: Выделить всё
jquery.js:3850 Uncaught TypeError: Cannot read property 'innerHTML' of null
at Function.r.load (tmpl.js:40)
at r (tmpl.js:23)
at $.<computed>.<computed>._initTemplates (jquery.fileupload-ui.js:661)
at $.<computed>.<computed>._initTemplates (jquery.ui.widget.js:148)
at $.<computed>.<computed>._initSpecialOptions (jquery.fileupload-ui.js:681)
at $.<computed>.<computed>._initSpecialOptions (jquery.ui.widget.js:148)
at $.<computed>.<computed>._create (jquery.fileupload.js:1439)
at $.<computed>.<computed>._create (jquery.ui.widget.js:148)
at $.<computed>.<computed>._super (jquery.ui.widget.js:133)
at $.<computed>.<computed>._create (jquery.fileupload-process.js:170)
Код, который у меня в my-upload-view:
Код: Выделить всё
<?php
/** @var \dosamigos\fileupload\FileUploadUI $this */
use yii\helpers\Html;
$context = $this->context;
?>
<!-- The file upload form used as target for the file upload widget -->
<?= Html::beginTag('div', $context->options); ?>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="col-lg-12">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span><?= Yii::t('fileupload', 'Add files') ?>...</span>
<?= $context->model instanceof \yii\base\Model && $context->attribute !== null
? Html::activeFileInput($context->model, $context->attribute, $context->fieldOptions)
: Html::fileInput($context->name, $context->value, $context->fieldOptions);?>
</span>
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<?= Html::endTag('div');?>
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 15:13
yiiliveext
Код: Выделить всё
'clientOptions' => [
'autoUpload' => 'true',
//...
]
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 16:10
yura1976
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 16:46
yiiliveext
Я же написал, что нужно переделать template, убрав ненужные кнопки, а не выдумывать свою вьюху, которая отдает html.
Код: Выделить всё
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error text-danger"></strong>
</td>
<td>
<p class="size"><?= Yii::t('fileupload', 'Processing') ?>...</p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
</td>
</tr>
{% } %}
</script>
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 16:48
yiiliveext
Если не получится, я завтра гляну, никогда не пользовался этим виджетом.
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 17:23
yura1976
yiiliveext писал(а): ↑2019.09.14, 16:46
Я же написал, что нужно переделать template, убрав ненужные кнопки, а не выдумывать свою вьюху, которая отдает html.
Код: Выделить всё
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error text-danger"></strong>
</td>
<td>
<p class="size"><?= Yii::t('fileupload', 'Processing') ?>...</p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
</td>
</tr>
{% } %}
</script>
Этот template - для отображения выбранных файлов и кнопок загрузки для уже выбранных. Т.е., Ваше предложение использовать uploadTemplateView - верное, но template - не тот (vendor/2amigos/yii2-file-upload-widget/src/views/upload.php). Я взял vendor/2amigos/yii2-file-upload-widget/src/views/form.php и убрал лишнее, своего ничего не добавлял. Теперь кнопка отображается та, что и должна, но в результате загрузки страницы консоль показывает ошибку, которую я привел, а при клике на кнопку "Загрузить файлы" ничего не происходит.
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 17:34
yura1976
Решил проблему. Нужно было не 'uploadTemplateView', а 'formView'. Но, спасибо, что навели на мысль. Сам бы я, наверное, еще долго думал бы.
Re: dosamigos\fileupload\FileUploadUI Убрать лишние кнопки
Добавлено: 2019.09.14, 17:37
yiiliveext
Я все правильно написал, именно тот template там и выводится по умолчанию, за форму отвечает formView, но я вижу вы и сами уже догадались.