当另一个字段值更改时,如何禁用 wagtail 中的一个字段?

时间:2021-04-20 08:38:30

标签: django django-forms wagtail

我有一个给定的 wagtail 形式:

from django import forms
from wagtail.admin.forms import WagtailAdminPageForm
from myapp.models import *

class MyClassForm(WagtailAdminPageForm):
    displayed_on_section = forms.ModelMultipleChoiceField(
        queryset=DisplayedOnSection.objects.all(), widget=forms.CheckboxSelectMultiple()
    )
    last_name = forms.CharField(required=False)
    # other fields

我的页面是这样的:

from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.models import Page

class MyClassPage(Page):
    content_panels = Page.content_panels + [
        FieldPanel('displayed_on_section'),
        FieldPanel('last_name')
    ]
    base_form_class = MyClassForm

现在假设我有 3 个显示的部分,例如:

o Profile Section
o Dashboard Section
o Feed Section

我希望如果用户选择 Feed Sectionlast_name 表单字段应该被禁用(如果可能,它的值变为空)。

是否有可能实现我正在尝试做的事情?有哪些方法可以做到?

附言我只是想知道如何做到这一点,我不需要完整的解决方案。

0 个答案:

没有答案