mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
Fixed #36354 -- Removed JavaScript workaround for browsers lacking :has()
CSS support.
This branch removes the JavaScript fallback added in the admin for the add user and change password templates/flows (Refs #34429). Django documents suport for "modern, web standards compliant browsers". See https://caniuse.com/css-has for info on browser support per version.
This commit is contained in:
parent
0ee06c04e0
commit
65bbdbd10b
@ -1,29 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
// Fallback JS for browsers which do not support :has selector used in
|
|
||||||
// admin/css/unusable_password_fields.css
|
|
||||||
// Remove file once all supported browsers support :has selector
|
|
||||||
try {
|
|
||||||
// If browser does not support :has selector this will raise an error
|
|
||||||
document.querySelector("form:has(input)");
|
|
||||||
} catch (error) {
|
|
||||||
console.log("Defaulting to javascript for usable password form management: " + error);
|
|
||||||
// JS replacement for unsupported :has selector
|
|
||||||
document.querySelectorAll('input[name="usable_password"]').forEach(option => {
|
|
||||||
option.addEventListener('change', function() {
|
|
||||||
const usablePassword = (this.value === "true" ? this.checked : !this.checked);
|
|
||||||
const submit1 = document.querySelector('input[type="submit"].set-password');
|
|
||||||
const submit2 = document.querySelector('input[type="submit"].unset-password');
|
|
||||||
const messages = document.querySelector('#id_unusable_warning');
|
|
||||||
document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword;
|
|
||||||
document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword;
|
|
||||||
if (messages) {
|
|
||||||
messages.hidden = usablePassword;
|
|
||||||
}
|
|
||||||
if (submit1 && submit2) {
|
|
||||||
submit1.hidden = !usablePassword;
|
|
||||||
submit2.hidden = usablePassword;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
option.dispatchEvent(new Event('change'));
|
|
||||||
});
|
|
||||||
}
|
|
@ -10,7 +10,3 @@
|
|||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
<link rel="stylesheet" href="{% static 'admin/css/unusable_password_field.css' %}">
|
<link rel="stylesheet" href="{% static 'admin/css/unusable_password_field.css' %}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block admin_change_form_document_ready %}
|
|
||||||
{{ block.super }}
|
|
||||||
<script src="{% static 'admin/js/unusable_password_field.js' %}" defer></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -77,5 +77,4 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form></div>
|
</form></div>
|
||||||
<script src="{% static 'admin/js/unusable_password_field.js' %}" defer></script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user