conditional_field
Allows for arbitrary showing and hiding of fields in the admin based on certain user input. Idea based on Wagtail UI+'s conditional visibility fields.
Installations
-
Add conditional field to your
INSTALLED_APPSINSTALLED_APPS = [ ... 'conditional_field' ... ] -
Run
python3 ./manage.py collectstatic
Example usage of the gcf conditional fields.
from wagtail import blocks
class Link(blocks.StructBlock):
text = CharBlockWithAttrs(
required=False,
label=_("Text"),
)
page = blocks.PageChooserBlock(
required=False,
label=_("Page"),
classname=(
"gcf "
"gcf-handler--choice "
"gcf-action--show--page "
),
)
document = DocumentChooserBlock(
required=False,
label=_("Document"),
classname=(
"gcf "
"gcf-handler--choice "
"gcf-action--show--document"
),
)
external_link = blocks.URLBlock(
required=False,
label=_("External Link"),
classname=(
"gcf "
"gcf-handler--choice "
"gcf-action--show--external_link"
),
)
email = blocks.EmailBlock(
required=False,
label=_("Email"),
classname=(
"gcf "
"gcf-handler--choice "
"gcf-action--show--email"
),
)
phone = blocks.CharBlock(
required=False,
label=_("Tel"),
placeholder=_("123-456-7890"),
validators=[
RegexValidator(
regex=r"^\+?[0-9\-\s\(\)]+$",
message=_("Enter a valid phone number."),
)
],
min_length=7,
max_length=14,
classname=(
# Example of multiple allowed
# choices for a single block
# We introduce fshow and fhide,
# these do not automatically do the opposite for false values.
# You would not want to use this in this context; it is just an example.
"gcf "
"gcf-handler--choice "
"gcf-action-any--fhide "
"gcf-action--fshow--email "
"gcf-action--fshow--tel"
),
)
choice = blocks.ChoiceBlock(
required=True,
choices=[
("page", "Page")
("document", "Document")
("external_link", "External")
("email", "Email Link")
("tel", "Telephone Link")
],
default="page",
label=_("Link Type"),
classname=(
"gcf "
"gcf-handler--choice"
),
widget=forms.RadioSelect,
)
hide_animation_fields_classname = (
'gcf '
'gcf-handler--animation '
'gcf-action-empty--hide '
'gcf-action-any--show'
)
class AnimatorBlock(blocks.StructBlock):
animation = blocks.ChoiceBlock(
choices=animations_choices,
required=False,
label=_("Animation"),
translatable=False,
classname=(
'gcf '
'gcf-handler--animation'
),
)
duration = blocks.IntegerBlock(
default=1000,
required=True,
translatable=False,
label=_("Duration"),
classname=hide_animation_fields_classname,
)
delay = blocks.IntegerBlock(
default=0,
required=True,
translatable=False,
label=_("Delay"),
classname=hide_animation_fields_classname,
)
Metadata
Release files for conditional-field 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| conditional_field-1.1.0.tar.gz | 12.7 kB | Without provenance | Details for conditional_field-1.1.0.tar.gz |
Release files / conditional_field-1.1.0.tar.gz
| Download URL | conditional_field-1.1.0.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74133883333f1dc4fd63a740dca248b9d16209cdce6ee1647567793ace1792b9
|
|
BLAKE2b-256 checksum How to use checksums |
9c0e316de8e5f05bdfee9226a7af57cfba91b1dba5da8949e08fe1512fd37d1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.6
|
Security for conditional-field 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.