Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 5, 2025

Conversation

BSd3v
Copy link
Contributor

@BSd3v BSd3v commented Apr 29, 2025

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
):
super().__init__(component_id, component_property)
self.allow_optional = allow_optional
self.allowed_wildcards = (MATCH, ALL, ALLSMALLER)
Copy link
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
};

@@ -56,7 +58,8 @@ def component_id_str(self) -> str:
return stringify_id(self.component_id)

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
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

Copy link
Contributor

@T4rk1n T4rk1n left a comment

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