More changes for pagemediaselect to avoid double inclusion of data-grav-field, and to disable when no files are found

This commit is contained in:
Flavio Copes
2015-12-30 20:39:37 +01:00
parent 7f5863a66c
commit f34a9d7638

View File

@@ -1,7 +1,8 @@
{% extends "forms/field.html.twig" %}
{% set options = {'': 'No file'} %}
{% for index, media in admin.page.media.all %}
{% set files = admin.page.media.all %}
{% for index, media in files %}
{% set option = {(index): index} %}
{% set options = options|merge(option) %}
{% endfor %}
@@ -9,11 +10,11 @@
{% block global_attributes %}
data-grav-selectize="{{ (field.selectize is defined ? field.selectize : {})|json_encode()|e('html_attr') }}"
data-grav-field="select"
{{ parent() }}
data-grav-disabled="{{ files is empty ? 'true' : 'false' }}"
data-grav-default="{{ field.default|json_encode()|e('html_attr') }}"
{% endblock %}
{% block input %}
{% if theme or plugin %}
The "pagemediaselect" field cannot be used in Themes or Plugins Blueprints. It's intended to be used for Pages blueprints.
Use the "file" type instead.
@@ -23,7 +24,7 @@
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
{% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
{% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
{% if field.disabled %}disabled="disabled"{% endif %}
{% if field.disabled or files is empty %}disabled="disabled"{% endif %}
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
@@ -35,6 +36,6 @@
{% endfor %}
</select>
</div>
{% if admin.page.media.all is empty %}Add files through the page media, or by dropping them in the page folder{% endif %}
{% if files is empty %}Add files through the page media, or by dropping them in the page folder{% endif %}
{% endif %}
{% endblock %}