Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda