mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 13:09:41 +02:00
Don't show on select
This commit is contained in:
parent
23ee19ba28
commit
2a9d8ce6ef
2 changed files with 15 additions and 4 deletions
|
@ -144,13 +144,13 @@ function openInNewTab(el, removeAttribute = false){
|
||||||
let investigatorSelect = document.querySelector("#id_investigator");
|
let investigatorSelect = document.querySelector("#id_investigator");
|
||||||
let assignSelfButton = document.querySelector("#investigator__assign_self");
|
let assignSelfButton = document.querySelector("#investigator__assign_self");
|
||||||
if (investigatorSelect && assignSelfButton) {
|
if (investigatorSelect && assignSelfButton) {
|
||||||
|
let selector = django.jQuery(investigatorSelect)
|
||||||
assignSelfButton.addEventListener('click', function() {
|
assignSelfButton.addEventListener('click', function() {
|
||||||
let currentUserId = this.getAttribute("data-user-id");
|
let currentUserId = this.getAttribute("data-user-id");
|
||||||
let currentUserName = this.getAttribute("data-user-name");
|
let currentUserName = this.getAttribute("data-user-name");
|
||||||
if (currentUserId && currentUserName){
|
if (selector && currentUserId && currentUserName){
|
||||||
// Logic borrowed from here:
|
// Logic borrowed from here:
|
||||||
// https://select2.org/programmatic-control/add-select-clear-items#create-if-not-exists
|
// https://select2.org/programmatic-control/add-select-clear-items#create-if-not-exists
|
||||||
let selector = django.jQuery(investigatorSelect)
|
|
||||||
// Set the value, creating a new option if necessary
|
// Set the value, creating a new option if necessary
|
||||||
if (selector.find(`option[value='${currentUserId}']`).length) {
|
if (selector.find(`option[value='${currentUserId}']`).length) {
|
||||||
selector.val(currentUserId).trigger("change");
|
selector.val(currentUserId).trigger("change");
|
||||||
|
@ -164,6 +164,17 @@ function openInNewTab(el, removeAttribute = false){
|
||||||
console.error("Could not assign current user.")
|
console.error("Could not assign current user.")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
selector.on('change', function() {
|
||||||
|
let selectedValue = this.value;
|
||||||
|
if (selectedValue === "" || selectedValue === null) {
|
||||||
|
// If no investigator is selected, show the 'Assign to Self' button
|
||||||
|
assignSelfButton.parentElement.style.display = 'flex';
|
||||||
|
} else {
|
||||||
|
// If an investigator is selected, hide the 'Assign to Self' button
|
||||||
|
assignSelfButton.parentElement.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
/** An IIFE for pages in DjangoAdmin that use a clipboard button
|
/** An IIFE for pages in DjangoAdmin that use a clipboard button
|
||||||
|
|
|
@ -174,7 +174,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{% elif field.field.name == "investigator" %}
|
{% elif field.field.name == "investigator" and not original_object.investigator %}
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<label aria-label="Assign yourself as the investigator"></label>
|
<label aria-label="Assign yourself as the investigator"></label>
|
||||||
<button id="investigator__assign_self"
|
<button id="investigator__assign_self"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue