Created
May 28, 2024 15:35
-
-
Save Crocoblock/be965b3804879d74d6a1c43b69134534 to your computer and use it in GitHub Desktop.
JetFormBuilder Unselectable radio
This file contains hidden or 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
<script> | |
document.addEventListener( 'DOMContentLoaded', function() { | |
if ( ! window?.JetPlugins?.hooks ) { | |
return; | |
} | |
const { | |
addAction, | |
} = window.JetPlugins.hooks; | |
addAction( | |
'jet.fb.input.makeReactive', | |
'unselectable-radio', | |
makeUnselectable | |
); | |
function makeUnselectable( input ) { | |
if ( ! input?.nodes?.length ) { | |
return; | |
} | |
if ( ! input.nodes[0].classList.contains( 'allow-unselect' ) ) { | |
return; | |
} | |
for ( const node of input.nodes ) { | |
node.addEventListener( | |
'click', | |
function() { | |
if ( input.value.current === this.value ) { | |
input.value.current = ''; | |
} | |
} | |
); | |
} | |
} | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment