mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
Add checkbox
This commit is contained in:
parent
196ab6323b
commit
44c4e2ef26
2 changed files with 43 additions and 1 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue