Admin action drop-down 'required' preventing saving updates

38 views
Skip to first unread message

Danny

unread,
Feb 18, 2021, 1:01:01 AM2/18/21
to Mezzanine Users

Hi all,

This is possibly a Django-2.2.18 related problem, but I thought I'd see if anyone else has experienced this and had a workaround.

I recently updated my website to Mezzanine 5.0.0a1 and Django 2.2.18, and after some reasonably thorough local testing, deployed it to the live website.

One of my fellow admins discovered something odd, which I've now confirmed on both local and deployed sites.

At the top of an Admin change list page, there's the standard action drop down (usually containing 'Delete selected <Model name>'). This is useful when you want to select some objects and delete them, but otherwise I've not customised it for any of the standard Mezzanine/Cartridge models I use.

What's now odd is that if you hit the 'Save' button at the bottom of the object list, a generic prompt pops up saying 'Please select an item in the list' pointing to this action drop down.

After some research, I discovered the following:

a) this pop up message is generic from HTML5, for a <select> form element that has the 'required' attribute: https://www.w3schools.com/TAGS/att_select_required.asp

b) this 'required' attribute is being added to the <select> element when the page is rendered, but only when DEBUG=False. That is, on my local development with DEBUG=True, the select element is not required (and Save works fine), but if I modify my local settings and set DEBUG=False, then required is forced on this element, and I get the same pop up as seen on the deployed server.

I've tried digging into the Django code to try and find out what's happening to render this field, but it seems to be fairly benign:

grapelli-safe template that renders the action drop down: https://github.com/stephenmcd/grappelli-safe/blob/master/grappelli_safe/templates/admin/actions.html#L3

django code that is the action form: https://github.com/django/django/blob/2.2.18/django/contrib/admin/helpers.py#L20

I'm not sure where the ChoiceField is being forced to required=True when DEBUG=False, nor how I can override this.

Any one got any ideas? Have you noticed this on your own deployments using Mezzanine 5.0.0a1?

Thanks for any help,

Seeya. Danny.

Daniel Montecillo

unread,
Feb 18, 2021, 10:05:07 AM2/18/21
to Mezzanine Users

Have you tried checking one of the forms used in the templates?
You can check there if required is explicitly declared.

Example:

    selection = forms.CharField(
        required=True,
        widget=forms.ChoiceField(attrs={"class": "form-control", "type": "text", }),
    )
--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mezzanine-users/a46283a7-99de-02ad-628f-26b80459403b%40gmail.com.
publickey - daniel.montecillo@montecillo.ca - 5be7637f.asc
signature.asc

Danny

unread,
Feb 18, 2021, 9:55:19 PM2/18/21
to Mezzanine Users
Hi again everyone,

I think I finally got to the bottom of my problem.

The Select widget  used for this admin dropdown *does* have the 'required' attribute by default, but there's Mezzanine javascript that removes this from this specific location in admin pages:

https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/core/static/mezzanine/js/admin/navigation.js#L6

In my case, the problem was that my website was hitting a Javascript error earlier on and thus this line wasn't executing properly or being skipped entirely. Part of this was that I had an old set of javascript files etc in 'static' on my webserver leftover from using Mezzanine 4.3.

Among other things,  I was missing the new jQuery version used by Mezzanine 5.0.0a1 and when I checked the developer console in my browser I could see a bunch of JS errors.

I manually ran python manage.py collectstatic, restarted the server, and now things appear to be working as expected.

So a word of advice for anyone else hitting similar upgrade issues: check the developer console in your browser for javascript errors, and make sure you have run collectstatic when you deploy!

Seeya. Danny.
Reply all
Reply to author
Forward
0 new messages