Allow dynamically changing in min and max in st.date_input#13549
Allow dynamically changing in min and max in st.date_input#13549lukasmasuch merged 8 commits intodevelopfrom
st.date_input#13549Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
|
@cursor review |
There was a problem hiding this comment.
Pull request overview
This pull request enables dynamic changing of min_value and max_value parameters in st.date_input by removing them from the whitelisted parameters that affect widget ID computation. When bounds change and the current value becomes invalid, the widget now automatically resets to its default value.
Changes:
- Removed
min_valueandmax_valuefrom thekey_as_main_identitywhitelist, keeping onlyformat(which has a known baseweb bug that prevents dynamic changes) - Added validation logic to detect when widget values fall outside new bounds and automatically reset to defaults
- Updated widget ID stability tests to verify that min/max changes don't trigger ID regeneration
- Added comprehensive unit tests and E2E tests covering dynamic bound changes for both single-date and range-date inputs
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 16 comments.
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/time_widgets.py | Added _validate_and_reset_date_value function to validate and reset values when bounds change; updated _date_input to use only format in key_as_main_identity and apply validation logic |
| lib/tests/streamlit/elements/date_input_test.py | Updated ID stability tests to reflect that min/max are no longer whitelisted; added new tests for dynamic bound changes, value preservation, and session state handling |
| e2e_playwright/st_date_input.py | Updated test app to use different min/max values when toggling to demonstrate dynamic bounds |
| e2e_playwright/st_date_input_test.py | Added E2E test case verifying that out-of-bounds values reset to defaults when bounds change |
…min-max-for-date-input
| # Now min_value=June 1, so March 1 is invalid and should reset to default (July 15) | ||
| assert at.date_input[0].value == date(2024, 7, 15) | ||
| # Anti-regression: ensure it didn't keep the old invalid value | ||
| assert at.date_input[0].value != date(2024, 3, 1) |
There was a problem hiding this comment.
Is this useful? Since if this were true, won't execution stop when the first assert fails?
There was a problem hiding this comment.
Removed it, agree that it is not super useful
| if current_value is None or not has_explicit_bounds: | ||
| return current_value, False | ||
|
|
||
| value_needs_reset = False |
There was a problem hiding this comment.
[nit] You could define this above the conditional check here and the return current_value, value_needs_reset in the conditional. It's jut a bit more readable because it reminds you what the two return values are for. But super nit.
sfc-gh-lwilby
left a comment
There was a problem hiding this comment.
LGTM when the e2e test is fixed (running now, so maybe already fixed).
Enable dynamic min_value and max_value changes for datetime_input when a key is provided, following the same pattern as st.date_input (PR #13549). Changes: - Updated key_as_main_identity to exclude min/max from element ID stability - Added _validate_datetime_value() to handle bound validation and value resets - Added logic to track explicit bounds and reset values when out of bounds - Added unit tests for dynamic min/max scenarios - Updated E2E tests to validate dynamic bounds behavior Co-Authored-By: Claude <[email protected]>
Describe your changes
Allow dynamically changing the
min_value,max_valueofst.date_inputwithout triggering an identity change / state reset. If the current selected value isn't in the range, it will be reset to the default value.GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.