Skip to content

Commit

Permalink
Add redirect after submission action
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 7, 2025
1 parent 1c4c288 commit bad4429
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
29 changes: 27 additions & 2 deletions djangocms_form_builder/actions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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"))
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fieldset.action-hide {
fieldset.action-hide, fieldset.empty {
display: none;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit bad4429

Please sign in to comment.