diff --git a/djangocms_form_builder/actions.py b/djangocms_form_builder/actions.py index 71865c6..861c753 100644 --- a/djangocms_form_builder/actions.py +++ b/djangocms_form_builder/actions.py @@ -1,6 +1,7 @@ import hashlib from django import forms +from django.apps import apps from django.core.exceptions import ImproperlyConfigured from django.core.mail import mail_admins, send_mail from django.core.validators import EmailValidator @@ -223,8 +224,8 @@ def execute(self, form, request): @register -class SubmitMessageAction(FormAction): - verbose_name = _("Submit message") +class SuccessMessageAction(FormAction): + verbose_name = _("Success message") class Meta: entangled_fields = { @@ -244,3 +245,27 @@ def execute(self, form, request): form.get_success_context = lambda *args, **kwargs: {"message": message} form.Meta.options["render_success"] = "djangocms_form_builder/actions/submit_message.html" form.Meta.options["redirect"] = None + + +if apps.is_installed("djangocms_link"): + from djangocms_link.fields import LinkFormField + from djangocms_link.helpers import get_link + + @register + class RedirectAction(FormAction): + verbose_name = _("Redirect after submission") + + class Meta: + entangled_fields = { + "action_parameters": [ + "redirect_link", + ] + } + + redirect_link = LinkFormField( + label=_("Link"), + required=True, + ) + + def execute(self, form, request): + form.Meta.options["redirect"] = get_link(self.get_parameter(form, "redirect_link")) diff --git a/djangocms_form_builder/static/djangocms_form_builder/css/actions_form.css b/djangocms_form_builder/static/djangocms_form_builder/css/actions_form.css index 2eab46e..4bea84c 100644 --- a/djangocms_form_builder/static/djangocms_form_builder/css/actions_form.css +++ b/djangocms_form_builder/static/djangocms_form_builder/css/actions_form.css @@ -1,3 +1,3 @@ -fieldset.action-hide { +fieldset.action-hide, fieldset.empty { display: none; } diff --git a/djangocms_form_builder/static/djangocms_form_builder/js/actions_form.js b/djangocms_form_builder/static/djangocms_form_builder/js/actions_form.js index 261aa14..283470f 100644 --- a/djangocms_form_builder/static/djangocms_form_builder/js/actions_form.js +++ b/djangocms_form_builder/static/djangocms_form_builder/js/actions_form.js @@ -1,7 +1,12 @@ $(function () { + 'use strict'; $('fieldset.action-auto-hide input[type="checkbox"][name="form_actions"]').each(function (index, element) { + const target = $('.' + $(element).attr("value")); if (element.checked) { - $("."+$(element).attr("value")).removeClass("action-hide"); + target.removeClass("action-hide"); + } + if (!target.find('.form-row:not(.hidden)').length) { + target.addClass("empty"); } $(element).on("change", function (event) { var element = event.target;