Skip to content
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

fix: toggle default value #395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix: toggle default value #395

wants to merge 1 commit into from

Conversation

mahatoankitkumar
Copy link
Collaborator

@mahatoankitkumar mahatoankitkumar commented Jan 30, 2025

Problem

The toggle component defaults to null instead of a boolean value when initially rendered, causing unexpected behavior until user interaction occurs.

Solution

Called the onChange event handler to properly handle the initial null state, ensuring the toggle always has a valid boolean value (true/false).

@mahatoankitkumar mahatoankitkumar requested a review from a team as a code owner January 30, 2025 07:00
@Datron Datron linked an issue Jan 31, 2025 that may be closed by this pull request
}
None => view! { <Toggle value=false on_change class name/> }.into_view(),
None => {
on_change.call(Value::Bool(false));
Copy link
Collaborator

@ayushjain17 ayushjain17 Jan 31, 2025

Choose a reason for hiding this comment

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

this would get triggered on every re-render
this should be dealt at the moment when the type is being chosen by the user

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

}
None => view! { <Toggle value=false on_change class name/> }.into_view(),
None => {
on_change.call(Value::Bool(false));
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

@@ -278,6 +278,9 @@ where
) {
(Ok(schema_type), Ok(enum_variants)) => {
let input_type = InputType::from((schema_type.clone(), enum_variants));
if input_type == InputType::Toggle {
config_value_ws.set(Value::Bool(false));
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is also at render time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The default value for boolean toggle is not set in forms
4 participants