Skip to content

fix(FormBuilder): correct radio checked state for falsy values (fixes #650) #828

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

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from

Conversation

vedant-jayale
Copy link

What does this PR do?

Fixes incorrect handling of radio inputs with falsy values (0, false, empty string) by replacing !$request with is_null($request) in FormBuilder.php.

Fixes #650

Why is this needed?

  • Bug: Radio buttons with value="0" showed as unchecked despite being selected
  • Root Cause: !$request evaluated all falsy values (0/false/"") as "missing"
  • Solution: is_null() specifically detects only truly missing fields (null)

Changes Made

  • Replaced !$request with is_null($request) in getRadioCheckedState()
  • Maintains backward compatibility (no breaking changes)
  • Aligns with standard HTML form behavior

Test Case | Before | After
value="0" | ❌ | ✅
value="1" | ✅ | ✅
Field not submitted | ✅ | ✅
  |

Fixes #650

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

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

This update in the getRadioCheckedState method is a smart fix that addresses an important edge case—previously, the use of !$request could incorrectly treat valid falsy values like 0 or false as missing input. By switching to is_null($request), the logic now correctly handles those values, ensuring that radio buttons reflect the proper checked state. The code remains clean and readable, and the inline comment clearly explains the rationale behind the change, making this a thoughtful and well-documented improvement.

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.

getRadioCheckedState - use is_null instead of !
2 participants