Sfoglia il codice sorgente

Hide 'Edit this item' link from chooser widget if edit_url is not supplied

Matt Westcott 2 anni fa
parent
commit
6a881e0a5d

+ 7 - 1
client/src/components/ChooserWidget/index.js

@@ -89,7 +89,13 @@ export class Chooser {
     }
     this.chooserElement.classList.remove('blank');
     if (this.editLink) {
-      this.editLink.setAttribute('href', newState[this.editLinkStateKey]);
+      const editUrl = newState[this.editLinkStateKey];
+      if (editUrl) {
+        this.editLink.setAttribute('href', editUrl);
+        this.editLink.classList.remove('u-hidden');
+      } else {
+        this.editLink.classList.add('u-hidden');
+      }
     }
   }
 

+ 1 - 1
wagtail/admin/templates/wagtailadmin/widgets/chooser.html

@@ -23,7 +23,7 @@
             {% if widget.show_edit_link %}
                 <li>
                     {% block edit_link %}
-                        <a href="{% block edit_chosen_item_url %}{{ edit_url }}{% endblock %}" class="edit-link button button-small button-secondary" target="_blank" rel="noreferrer">{{ widget.link_to_chosen_text }}</a>
+                        <a href="{% block edit_chosen_item_url %}{{ edit_url }}{% endblock %}" class="edit-link button button-small button-secondary{% if not edit_url %} u-hidden{% endif %}" target="_blank" rel="noreferrer">{{ widget.link_to_chosen_text }}</a>
                     {% endblock %}
                 </li>
             {% endif %}