Resolve error when specifying 'slug' as a read-only field ()

pull/11601/head
Rohit Sharma 2024-01-11 18:01:00 +00:00 zatwierdzone przez Matt Westcott
rodzic 222cf7de72
commit da31733b93
2 zmienionych plików z 24 dodań i 1 usunięć

Wyświetl plik

@ -78,7 +78,11 @@ class TitleFieldPanel(FieldPanel):
actions = [widget.attrs.get("data-action", None)] + self.apply_actions
attrs["data-action"] = " ".join(filter(None, actions))
targets = [self.get_target_selector(target) for target in panel.targets]
targets = [
self.get_target_selector(target)
for target in panel.targets
if target in self.form.fields
]
attrs["data-w-sync-target-value"] = ", ".join(filter(None, targets))
placeholder = self.get_placeholder()

Wyświetl plik

@ -2260,6 +2260,25 @@ class TestTitleFieldPanel(WagtailTestUtils, TestCase):
"focus->w-sync#check blur->w-sync#apply change->w-sync#apply keyup->w-sync#apply",
)
def test_form_without_slugfield(self):
html = self.get_edit_handler_html(ObjectList([TitleFieldPanel("title")]))
self.assertIsNotNone(html.find(attrs={"class": "w-panel title"}))
attrs = html.find("input").attrs
self.assertEqual(attrs["data-w-sync-target-value"], "")
def test_form_with_readonly_slugfield(self):
html = self.get_edit_handler_html(
ObjectList([TitleFieldPanel("title"), FieldPanel("slug", read_only=True)]),
instance=EventPage(),
)
self.assertIsNotNone(html.find(attrs={"class": "w-panel title"}))
attrs = html.find("input").attrs
self.assertEqual(attrs["data-w-sync-target-value"], "")
def test_not_using_apply_actions_if_live(self):
"""
If the Page (or any model) has `live = True`, do not apply the actions by default.