Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#25766 closed Bug (needsinfo)

adding javascript "this.disabled" invalidate ManyToManyField

Reported by: liwee Owned by: nobody
Component: contrib.admin Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by liwee)

With just models.py and admin.py, I was able to save a poll without any problems.
But if you add onClick="this.disabled=true; this.form.submit()", even if you try to add qn to the poll, it will not get saved

submit_line.html

{% if show_save_and_continue %}<input onClick="this.disabled=true; this.form.submit();" type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />{% endif %}

models.py

from django.db import models

class Question(models.Model):
    qn = models.CharField(max_length=200)

    def __unicode__(self):
        return self.qn
			
class Poll(models.Model):
    name = models.CharField(max_length=200)
    qn = models.ManyToManyField(Question)

admin.py

from django.contrib import admin
from .models import *

class PollAdmin(admin.ModelAdmin):
	filter_horizontal = ('qn',)

admin.site.register(Poll, PollAdmin)
admin.site.register(Question)

Change History (4)

comment:1 Changed 7 years ago by liwee

Description: modified (diff)

comment:2 Changed 7 years ago by Tim Graham

Resolution: needsinfo
Status: newclosed

It's not clear to me how or why this is a bug in Django. It seems to me that onClick="this.disabled=true; this.form.submit();" is something that you or a third-party package you are using added.

comment:3 Changed 7 years ago by liwee

I added the javascript to prevent multiple button clicks; Whilst submitting credit card details for payment, some sites disable the submit button to prevent multiple payments, I am just trying to mimic that behaviour.

If you comment filter_horizontal = ('qn',) and try again, saving will not cause a problem. Originally, I had the impression that it was a problem with ManyToManyField because I was able to save other fields without a problem.

comment:4 Changed 7 years ago by Tim Graham

I think this is covered by #16730.

Note: See TracTickets for help on using tickets.
Back to Top