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(allow binding non string values to checkboxes) #770

Merged
merged 3 commits into from Sep 16, 2020
Merged

fix(allow binding non string values to checkboxes) #770

merged 3 commits into from Sep 16, 2020

Conversation

ryangjchandler
Copy link
Contributor

This PR fixes an issue where non-string values couldn't be bound to a checkbox's value. An example would be trying to bind an integer / number:

The value of the checkbox would actually be "on" due to the typeof value === 'string' check inside of the checkbox handler. This PR replaces that check with a value truth check and makes sure that it's not a boolean, then casts the value to a string using String(value).

This could be done in user-land using x-bind:value="String(100)" or template literals x-bind:value="${value}" but I'd say that it's a bit of a bug with the framework.

@ryangjchandler
Copy link
Contributor Author

@calebporzio Hold off on this one for a second, just found an issue with these changes.

@ryangjchandler
Copy link
Contributor Author

@calebporzio Ready for review now - there was a problem where trying to bind an integer 0 wouldn't work because it was considered "falsy", sorted that.

@KevinBatdorf originally found this problem too btw, in case he wanted to check if this fix works for him. From the new test, it looks like it will sort it out.

@calebporzio
Copy link
Collaborator

Ok, thanks Ryan.

Yeah, this seems like a bug and a good fix. Thanks!

@calebporzio calebporzio merged commit dd43c48 into alpinejs:master Sep 16, 2020
@ryangjchandler ryangjchandler deleted the fix/non-boolean-values-checkbox-bindinig branch September 16, 2020 15:15
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.

None yet

2 participants