Fix fill modifier for radio buttons #4101
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.