Skip to content

Commit

Permalink
Fix form actions in Wagtail >= 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Jan 30, 2024
1 parent 7e67c31 commit 5597f78
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
34 changes: 31 additions & 3 deletions wagtail_modeladmin/templates/modeladmin/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,46 @@
<ul>
<li class="actions footer__container">
{% block form_actions %}
<div class="dropdown dropup dropdown-button match-width">
{% wagtail_version 6 0 as wagtail60 %}

{% fragment as default_action_item %}
<button
type="submit"
class="button action-save button-longrunning"
class="button action-save button-longrunning w-w-full"
data-controller="w-progress"
data-action="w-progress#activate"
data-w-progress-active-value="{% trans 'Saving…' %}"
>
{% icon name="spinner" %}
<em data-w-progress-target="label">{% trans 'Save' %}</em>
</button>
</div>
{% endfragment %}

{% fragment as more_action_items %}
{% block more_action_items %}{% endblock %}
{% endfragment %}

{% if wagtail60 %}
{% comment %}
HACK:
Strip the fragment to check if the block has been overridden
with non-empty content, similar to {% fragment stripped %} in
Wagtail 6.0, which we can't use without having separate block
names for pre- and post-6.0 versions.
{% endcomment %}
{% if more_action_items.strip %}
{% dropdown_button button=default_action_item toggle_icon="arrow-up" %}
{{ more_action_items }}
{% enddropdown_button %}
{% else %}
{{ default_action_item }}
{% endif %}
{% else %}
<div class="dropdown dropup dropdown-button match-width">
{{ default_action_item }}
{{ more_action_items }}
</div>
{% endif %}
{% endblock %}
</li>
</ul>
Expand Down
25 changes: 8 additions & 17 deletions wagtail_modeladmin/templates/modeladmin/edit.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
{% extends "modeladmin/create.html" %}
{% load i18n wagtailadmin_tags %}
{% load i18n wagtailadmin_tags modeladmin_tags %}

{% block header %}
{% include "modeladmin/includes/header_with_history.html" with title=view.get_page_title subtitle=view.get_page_subtitle icon=view.header_icon merged=1 latest_log_entry=latest_log_entry history_url=history_url %}
{% endblock %}

{% block form_action %}{{ view.edit_url }}{% endblock %}

{% block form_actions %}
<div class="dropdown dropup dropdown-button match-width">
<button
type="submit"
class="button action-save button-longrunning"
data-controller="w-progress"
data-action="w-progress#activate"
data-w-progress-active-value="{% trans 'Saving…' %}"
>
{% icon name="spinner" %}
<em data-w-progress-target="label">{% trans 'Save' %}</em>
</button>

{% if user_can_delete %}
{% block more_action_items %}
{% wagtail_version 6 0 as wagtail60 %}
{% if user_can_delete %}
{% if wagtail60 %}
<a href="{{ view.delete_url }}" class="button">{% trans "Delete" %}</a>
{% else %}
<div class="dropdown-toggle">{% icon name="arrow-up" %}</div>
<ul>
<li><a href="{{ view.delete_url }}" class="shortcut">{% trans "Delete" %}</a></li>
</ul>
{% endif %}

</div>
{% endif %}
{% endblock %}

0 comments on commit 5597f78

Please sign in to comment.