diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js index b612d13445e1e5268a7e3957903eb4bf85ad32f9..4da6488ecd9eb71661e0e3cc236e7196e41b1265 100644 --- a/Resources/js/widget/file_upload.js +++ b/Resources/js/widget/file_upload.js @@ -141,6 +141,10 @@ fileuploadprocessalways: updateButtonVisibility }); + if(options.disabled || options.readonly) { + $button.fileupload('disable'); + } + }; })(jQuery); diff --git a/Resources/views/Form/file_upload.html.twig b/Resources/views/Form/file_upload.html.twig index f398994fd44995bd9e9f925cc73570ae7e017d82..53f72846affa86a133413b7c15f9495e452a6f73 100644 --- a/Resources/views/Form/file_upload.html.twig +++ b/Resources/views/Form/file_upload.html.twig @@ -17,7 +17,10 @@ {% block file_upload_widget %} <div id="{{ id }}" {{ block('widget_container_attributes') }} {{ block('widget_only_attributes') -}} data-download-prototype="{{ block('file_upload_entry_prototype')|e }}" - data-upload-prototype="{{ block('file_upload_progress_prototype')|e }}"> + data-upload-prototype="{{ block('file_upload_progress_prototype')|e }}" + {% if disabled %}data-disabled="disabled"{% endif -%} + {% if read_only %}data-readonly="readonly"{% endif -%} + > <div class="fileinput-entries"> {%- if value is not empty %} {%- if multiple %} @@ -30,7 +33,7 @@ {%- set file = file|default([]) %} <p class="template-download"> <input type="hidden" name="{{ full_name }}{% if multiple %}[]{% endif %}" value="{{ file.id|default }}"/> - <button class="btn btn-xs btn-danger delete" title="{% trans %}button.delete{% endtrans %}"> + <button class="btn btn-xs btn-danger delete" title="{% trans %}button.delete{% endtrans %}" {%- if disabled or read_only %} disabled="disabled"{% endif -%}> {{- irstea_icon('trash') -}} </button> <span class="name"> <a{% if file %} href="{{ path('file_upload_get', {id: file.id, token: csrfToken}) }}"{% endif %}>{{ file.originalFilename|default }}</a> @@ -45,7 +48,10 @@ </div> <span class="btn btn-primary fileinput-button"> <span>{{ irstea_icon('upload') }} {% trans %}button.upload{% endtrans %}</span> - <input type="file" name="_hack_{{ full_name }}"{% if multiple %} multiple="multiple"{% endif %}/> + <input type="file" name="_hack_{{ full_name }}" + {%- if multiple %} multiple="multiple"{% endif -%} + {%- if disabled or read_only %} disabled="disabled"{% endif -%} + /> </span> </div> {% endblock file_upload_widget %}