Skip to content

adds allow_optional to State and Input to place no value as the placeholders#3294

Merged
T4rk1n merged 9 commits into
plotly:devfrom
BSd3v:feat/3067
May 5, 2025
Merged

adds allow_optional to State and Input to place no value as the placeholders#3294
T4rk1n merged 9 commits into
plotly:devfrom
BSd3v:feat/3067

Conversation

@BSd3v

@BSd3v BSd3v commented Apr 29, 2025

Copy link
Copy Markdown
Contributor

Sometimes there is a need to have conditional inputs/states in callbacks, this allows this to happen by passing the conditions to the clientside to be parsed and null values passed back.

This is accessible by allow_optional=True on the Input/State.

fixes: #3067

@gvwilson gvwilson added feature something new P1 needed for current cycle community community contribution labels Apr 30, 2025
Comment thread dash/dependencies.py Outdated
):
super().__init__(component_id, component_property)
self.allow_optional = allow_optional
self.allowed_wildcards = (MATCH, ALL, ALLSMALLER)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a class attribute before, it doesn't change on the object and I mistyped the typing on L37 it should finish in = () to be a class attribute.

Searching for reference usage, there is none, I think it could actually be removed. The actual check happens on the frontend and they are defined here:

const allowedWildcards = {
Output: {ALL, MATCH},
Input: wildcards,
State: wildcards
};

Comment thread dash/dependencies.py Outdated
def to_dict(self) -> dict:
return {"id": self.component_id_str(), "property": self.component_property}
specs = {"id": self.component_id_str(), "property": self.component_property}
return {**specs, "allow_optional": True} if self.allow_optional else specs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda weird to read, should be:

if self.allow_optional:
    specs["allow_optional"] = True
return specs

@T4rk1n T4rk1n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Look good, just a minor code style comment.

@T4rk1n T4rk1n merged commit 692298e into plotly:dev May 5, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution feature something new P1 needed for current cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow optional callback inputs

3 participants