Skip to content

Commit 745f973

Browse files
committed
Fix form validation for redirect action
1 parent 578087b commit 745f973

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

djangocms_form_builder/actions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def get_action_class(action):
5656
return _action_registry.get(action, None)
5757

5858

59+
def get_hash(action_class):
60+
return hashlib.sha1(action_class.__name__.encode("utf-8")).hexdigest()
61+
62+
5963
class ActionMixin:
6064
"""Adds action form elements to Form plugin admin"""
6165

@@ -280,9 +284,13 @@ class Meta:
280284

281285
redirect_link = LinkFormField(
282286
label=_("Link"),
283-
required=True,
284287
)
285288

289+
def __init__(self, *args, **kwargs):
290+
super().__init__(*args, **kwargs)
291+
if args:
292+
self.fields["redirect_link"].required = get_hash(RedirectAction) in args[0].get("form_actions", [])
293+
286294
def execute(self, form, request):
287295
form.Meta.options["redirect"] = get_link(
288296
self.get_parameter(form, "redirect_link")

0 commit comments

Comments
 (0)