kopia lustrzana https://github.com/wagtail/wagtail
Defer validation on FieldPanel unless required_on_save passed
rodzic
d0e106b403
commit
a56888a7ab
|
@ -25,6 +25,7 @@ class FieldPanel(Panel):
|
|||
disable_comments=None,
|
||||
permission=None,
|
||||
read_only=False,
|
||||
required_on_save=False,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(**kwargs)
|
||||
|
@ -33,6 +34,7 @@ class FieldPanel(Panel):
|
|||
self.disable_comments = disable_comments
|
||||
self.permission = permission
|
||||
self.read_only = read_only
|
||||
self.required_on_save = required_on_save
|
||||
|
||||
def clone_kwargs(self):
|
||||
kwargs = super().clone_kwargs()
|
||||
|
@ -42,6 +44,7 @@ class FieldPanel(Panel):
|
|||
disable_comments=self.disable_comments,
|
||||
permission=self.permission,
|
||||
read_only=self.read_only,
|
||||
required_on_save=self.required_on_save,
|
||||
)
|
||||
return kwargs
|
||||
|
||||
|
@ -52,6 +55,9 @@ class FieldPanel(Panel):
|
|||
opts = {
|
||||
"fields": [self.field_name],
|
||||
}
|
||||
if not self.required_on_save:
|
||||
opts["defer_required_on_fields"] = [self.field_name]
|
||||
|
||||
if self.widget:
|
||||
opts["widgets"] = {self.field_name: self.widget}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class TitleFieldPanel(FieldPanel):
|
|||
**kwargs,
|
||||
):
|
||||
kwargs["classname"] = classname
|
||||
kwargs.setdefault("required_on_save", True)
|
||||
self.apply_if_live = apply_if_live
|
||||
self.placeholder = placeholder
|
||||
self.targets = targets
|
||||
|
|
|
@ -151,6 +151,8 @@ class CreateView(WagtailAdminTemplateMixin, HookResponseMixin, View):
|
|||
parent_page=self.parent_page,
|
||||
for_user=self.request.user,
|
||||
)
|
||||
if self.action_name == "save":
|
||||
self.form.defer_required_fields()
|
||||
|
||||
if self.form.is_valid():
|
||||
return self.form_valid(self.form)
|
||||
|
@ -243,7 +245,7 @@ class CreateView(WagtailAdminTemplateMixin, HookResponseMixin, View):
|
|||
self.set_default_privacy_setting()
|
||||
|
||||
# Save revision
|
||||
self.page.save_revision(user=self.request.user, log_action=True)
|
||||
self.page.save_revision(user=self.request.user, log_action=True, clean=False)
|
||||
|
||||
# Save subscription settings
|
||||
self.subscription.page = self.page
|
||||
|
|
|
@ -489,6 +489,9 @@ class EditView(WagtailAdminTemplateMixin, HookResponseMixin, View):
|
|||
for_user=self.request.user,
|
||||
)
|
||||
|
||||
if self.action_name == "save":
|
||||
self.form.defer_required_fields()
|
||||
|
||||
if self.form.is_valid() and not self.locked_for_user:
|
||||
return self.form_valid(self.form)
|
||||
else:
|
||||
|
@ -551,6 +554,7 @@ class EditView(WagtailAdminTemplateMixin, HookResponseMixin, View):
|
|||
user=self.request.user,
|
||||
log_action=True, # Always log the new revision on edit
|
||||
previous_revision=self.previous_revision,
|
||||
clean=False,
|
||||
)
|
||||
|
||||
self.add_save_confirmation_message()
|
||||
|
|
Ładowanie…
Reference in New Issue