-
-
Save marcus-at-localhost/d7ba43e1cf6cb7e6aeb9e77f32a7662b 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