-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 fill modifier for radio buttons #4101
Fix fill modifier for radio buttons #4101
Conversation
This is a good bug find! Would it not be simpler to only dispatch the fill/change event on a checked radio? Or is there another context in which a radio could dispatch a change event when unchecked? |
@ekwoka I made the least intrusive change possible. I thought the same thing about the change event, but when debugging I discovered the |
This is true. The change you made is definitely inline with the existing decisions. |
Perfect, thanks! |
This fixes filling model data based on which radio button is checked when the page loads. A very simple example can be found here and this PR also includes a test.
In the Codepen, I expected that
type
in the Alpine data would be set to 'second' after page load and that the 'Second' radio button would be checked. However,type
is set to 'first' and the 'First' radio button is checked instead.I did a little bit of debugging and figured out that a
change
event is being triggered when the.fill
modifier is present. Removing it from the first radio button (second example in the Codepen) makes it work as expected, but it should still work when the modifier is present by filling based on which radio button is currently checked.The
getInputValue
function has been updated to take into account whether a radio button is checked, if not it will return thecurrentValue
. I loosely based the changes on how checkboxes are handled.I tested it with checkboxes (third example in the Codepen) and that appears to be working correctly.