|
1
|
"use strict"; |
|
2
|
// Fallback JS for browsers which do not support :has selector used in |
|
3
|
// admin/css/unusable_password_fields.css |
|
4
|
// Remove file once all supported browsers support :has selector |
|
5
|
try { |
|
6
|
// If browser does not support :has selector this will raise an error |
|
7
|
document.querySelector("form:has(input)"); |
|
8
|
} catch (error) { |
|
9
|
console.log("Defaulting to javascript for usable password form management: " + error); |
|
10
|
// JS replacement for unsupported :has selector |
|
11
|
document.querySelectorAll('input[name="usable_password"]').forEach(option => { |
|
12
|
option.addEventListener('change', function() { |
|
13
|
const usablePassword = (this.value === "true" ? this.checked : !this.checked); |
|
14
|
const submit1 = document.querySelector('input[type="submit"].set-password'); |
|
15
|
const submit2 = document.querySelector('input[type="submit"].unset-password'); |
|
16
|
const messages = document.querySelector('#id_unusable_warning'); |
|
17
|
document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword; |
|
18
|
document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword; |
|
19
|
if (messages) { |
|
20
|
messages.hidden = usablePassword; |
|
21
|
} |
|
22
|
if (submit1 && submit2) { |
|
23
|
submit1.hidden = !usablePassword; |
|
24
|
submit2.hidden = usablePassword; |
|
25
|
} |
|
26
|
}); |
|
27
|
option.dispatchEvent(new Event('change')); |
|
28
|
}); |
|
29
|
} |
|
30
|
|