Skip to content

Commit

Permalink
Make field groups work on submission edit as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Nov 26, 2024
1 parent d1014dd commit 3ab2b60
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
4 changes: 2 additions & 2 deletions hypha/apply/funds/templates/funds/application_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ <h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applicat
{% for field in form %}
{% if field.field %}
{% if field.field.multi_input_field %}
{% include "forms/includes/multi_input_field.html" with is_application=True %}
{% include "forms/includes/multi_input_field.html" %}
{% else %}
{% include "forms/includes/field.html" with is_application=True %}
{% include "forms/includes/field.html" %}
{% endif %}
{% else %}
{% if field.group_number > 1 %}
Expand Down
6 changes: 3 additions & 3 deletions hypha/apply/funds/templates/funds/application_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
{% for field in form %}
{% if field.field %}
{% if field.field.multi_input_field %}
{% include "forms/includes/multi_input_field.html" with is_application=True %}
{% include "forms/includes/multi_input_field.html" %}
{% else %}
{% include "forms/includes/field.html" with is_application=True %}
{% include "forms/includes/field.html" %}
{% endif %}
{% else %}
{{ field.block }}
Expand All @@ -46,4 +46,4 @@
</div>

</div>
{% endblock %}
{% endblock %}
12 changes: 0 additions & 12 deletions hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
)
from hypha.apply.projects.forms import ProjectCreateForm
from hypha.apply.review.models import Review
from hypha.apply.stream_forms.blocks import GroupToggleBlock
from hypha.apply.todo.options import PROJECT_WAITING_PAF
from hypha.apply.todo.views import add_task_to_user
from hypha.apply.users.decorators import (
Expand Down Expand Up @@ -1575,24 +1574,13 @@ def get_form_class(self):
When trying to save as draft, this method will return a version of form
class that doesn't validate required fields while saving.
The method also disables any group toggle fields in the form, as they
are not supported on edit forms.
Returns:
class: The form class for the view.
"""
is_draft = True if "save" in self.request.POST else False
form_fields = self.object.get_form_fields(
draft=is_draft, form_data=self.object.raw_data, user=self.request.user
)
field_blocks = self.object.get_defined_fields()
for field_block in field_blocks:
if (
isinstance(field_block.block, GroupToggleBlock)
and not self.object.is_draft
):
# Disable group toggle field as it is not supported on edit forms.
form_fields[field_block.id].disabled = True
return type(
"WagtailStreamForm", (self.object.submission_form_class,), form_fields
)
Expand Down
6 changes: 3 additions & 3 deletions hypha/apply/templates/forms/includes/field.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% load i18n util_tags nh3_tags markdown_tags heroicons %}

{% with widget_type=field|widget_type field_type=field|field_type %}
<div class="form__group {{ field.id_for_label }} form__group--{{ widget_type }} {% if widget_type == 'checkbox_input' %} form__group--checkbox{% endif %}{% if widget_type == 'clearable_file_input' or widget_type == 'multi_file_input' or widget_type == 'single_file_field_widget' or widget_type == 'multi_file_field_widget' %} form__group--file{% endif %}{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}{% if is_application and field.field.grouper_for %} form-fields-grouper{% endif %}"
{% if is_application and field.field.grouper_for %}
<div class="form__group {{ field.id_for_label }} form__group--{{ widget_type }} {% if widget_type == 'checkbox_input' %} form__group--checkbox{% endif %}{% if widget_type == 'clearable_file_input' or widget_type == 'multi_file_input' or widget_type == 'single_file_field_widget' or widget_type == 'multi_file_field_widget' %} form__group--file{% endif %}{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}{% if field.field.grouper_for %} form-fields-grouper{% endif %}"
{% if field.field.grouper_for %}
data-grouper-for="{{ field.field.grouper_for }}"
data-toggle-on="{{ field.field.choices.0.0 }}"
data-toggle-off="{{ field.field.choices.1.0 }}"
{% endif %}
{% if is_application and field.field.group_number > 1 %}
{% if field.field.group_number > 1 %}
data-hidden="{% if not show_all_group_fields and not field.field.visible %}true{% else %}false{% endif %}"
data-required="{{ field.field.required_when_visible }}"
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions hypha/apply/templates/forms/includes/multi_input_field.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load heroicons %}
<div
class="form__item{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if not field.initial %} multi-input-field-hidden{% endif %}{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
{% if is_application and field.field.group_number > 1 %} data-hidden="{% if not show_all_group_fields %}true{% else %}false{% endif %}"{% endif %}
class="form__item{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if not field.initial %} multi-input-field-hidden{% endif %}{% if field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
{% if field.field.group_number > 1 %} data-hidden="{% if not show_all_group_fields %}true{% else %}false{% endif %}"{% endif %}
data-multi-field-for="{{ field.field.multi_input_id }}"
>
{{ field }}
Expand All @@ -11,7 +11,7 @@

{% if field.field.multi_input_add_button %}
<button
class="button button--primary button--narrow multi-input-add-btn my-2{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
class="button button--primary button--narrow multi-input-add-btn my-2{% if field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
type="button" data-multi-field-id="{{ field.field.multi_input_id }}"
data-multi-visibility-index="{{ field.field.visibility_index }}"
data-multi-max-index="{{ field.field.max_index }}"
Expand Down

0 comments on commit 3ab2b60

Please sign in to comment.