Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Confirmation button on save button like delete already has

I want to modify Django admin interface.

There is delete button already has a confirmation page. But I want to add this confirmation to save or change buttons. Actually not exactly the same delete button.

I want to change default admin buttons like this JS or I want to add JS to admin buttons.

<input type="submit" onclick="linkSubmit('http://www.google.com')" value="Submit">
<p id="demo"></p>

<script>
function linkSubmit(link) {
  let text = "Press a button!\nEither OK or Cancel.";
  if (confirm(text) == true) {
    window.location.href = link;
  } else {
  }
  document.getElementById("demo").innerHTML = text;
}
</script>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

We found the solution in the files of the delete command. We took copies of the files confirm to the delete function and connected them to the confirm button.

We still can't give it as a alert. Gives confirmation on a another page.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Assuming there is already some type of event listener for the button I would add my own custom function as an additional listener for the on click event. Then I would put in my if(confirm) logic and call event.stopImmediatePropagation() as needed to prevent the original functionality from occuring.

about 4 years ago · Juan Pablo Isaza Denunciar

0

  1. Create templates/admin/change_form.html in your project:
{% extends "admin/change_form.html" %}

{% block admin_change_form_document_ready %}{{ block.super }}
<script id="django-admin-form-change-constants"
        data-model-name="{{ opts.model_name }}">
    let modelName = document.getElementById('django-admin-form-change-constants').dataset.modelName;
    let form = document.getElementById(modelName + '_form');
    form.addEventListener('submit', (event) => {
        let text = "Press a button!\nEither OK or Cancel.";
        if (!confirm(text)) {
            event.preventDefault();
        }
    });
</script>
{% endblock %}
  1. Set DIRS in myproject/settings.py to point to your project's templates directory:
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        ...
    }
]

References:

  • https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#overriding-admin-templates
  • https://docs.djangoproject.com/en/4.1/howto/overriding-templates/#overriding-from-the-project-s-templates-directory
  • https://github.com/django/django/blob/4.1/django/contrib/admin/templates/admin/change_form.html#L66-L74
  • https://github.com/django/django/blob/4.1/django/contrib/admin/static/admin/js/change_form.js#L5
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda