Add checkbox

This commit is contained in:
zandercymatics 2024-03-14 15:46:29 -06:00
parent 196ab6323b
commit 44c4e2ef26
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 43 additions and 1 deletions

View file

@ -76,6 +76,48 @@ function openInNewTab(el, removeAttribute = false){
prepareDjangoAdmin();
})();
/** An IIFE for pages in DjangoAdmin that use a clipboard button
*/
(function (){
function copyToClipboardAndChangeIcon(button) {
// Assuming the input is the previous sibling of the button
let input = button.previousElementSibling;
// Copy input value to clipboard
if (input) {
navigator.clipboard.writeText(input.value).then(function() {
// Change the icon to a checkmark on successful copy
let buttonIcon = button .querySelector('.usa-button__clipboard use');
if (buttonIcon) {
let currentHref = buttonIcon.getAttribute('xlink:href');
let baseHref = currentHref.split('#')[0];
// Append the new icon reference
buttonIcon.setAttribute('xlink:href', baseHref + '#check');
setTimeout(function() {
// Change back to the copy icon
buttonIcon.setAttribute('xlink:href', currentHref);
}, 2000);
}
}).catch(function(error) {
console.error('Clipboard copy failed', error);
});
}
}
function handleClipboardButtons() {
clipboardButtons = document.querySelectorAll(".usa-button__clipboard")
clipboardButtons.forEach((button) => {
button.addEventListener("click", ()=>{copyToClipboardAndChangeIcon(button)});
});
}
handleClipboardButtons();
})();
/**
* An IIFE to listen to changes on filter_horizontal and enable or disable the change/delete/view buttons as applicable
*

View file

@ -21,7 +21,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% elif field.field.name == "email" %}
<div class="admin-icon-group">
{{ field.field }}
<button class="usa-button usa-button__icon padding-05" type="button">
<button class="usa-button usa-button__icon usa-button__clipboard" type="button">
<svg
class="usa-icon"
>