Last active
June 10, 2023 08:44
-
-
Save corlaez/5f5f6f43524634ebd702bdf4fd936552 to your computer and use it in GitHub Desktop.
htmx cookbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is meant to be in a html head script tag | |
// checkboxes are very inconvenient in html and will serialize nothing when the checkbox is unchecked | |
// instead of using hx-vals and writting a bit of JSON each time you have a checkbox I decided to fix it globally: | |
window.onload = function() { | |
document.body.addEventListener('htmx:configRequest', function(evt) { | |
const isInput = evt.detail.elt.tagName == 'INPUT'; | |
const isCheckbox = evt.detail.elt.type == 'checkbox'; | |
const isNotChecked = evt.detail.elt.checked == false; | |
if(isInput && isCheckbox && isNotChecked) { | |
const name = evt.detail.elt.name; | |
evt.detail.parameters[name] = false; | |
} | |
}); | |
} | |
// PS there should be an input type checkbox2 that behaves properly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment