Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!