Adding `num_min` parameter break order of orderable related object during creation only
See original GitHub issueIssue Summary
During creation only, adding min_num
parameter to InlinePanel
breaks the order of orderable related object when extra forms are added by clicking “Add {obj_name}” button.
Steps to Reproduce
- Set
min_num
forInlinePanel
for related links to any desirable number(e.g 2) inBlogPage
class
from /wagtaildemo/demo/models.py
lines: 423-429
BlogPage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('date'),
StreamFieldPanel('body'),
InlinePanel('carousel_items', label="Carousel items"),
InlinePanel('related_links', label="Related links", min_num=2),
]
- In admin interface create a new “Blog page”
- Fill in 2 minimum required forms for related links (for visibility I titled links: ‘Link 1’, ‘Link 2’ etc)
- Click ‘add related links’ button to add extra form
- Fill in the extra form
- Repeat steps 4 and 5 N-times
- Save draft of the page
- After saving you can see that the order of related links is incorrect: extra links (Link 3 - Link N) become first links in the list and Link 1 and Link 2 moved to the bottom.
It seems that adding min_num
parameter breaks javascript. If min_num
parameter is not set, the value
attr of hidden input ‘ORDER’ for the first form in the formset is adding. However, when I add min_num
parameter, the value
attr of ‘ORDER’ for the first N required forms in the formset, is missing (is not adding), however for extra forms, the value
of ‘ORDER’ is adding.
Technical details
Tried in 2 environments:
First
- Python 3.4.3
- Django==1.10.8
- wagtail==1.12.2
- Browser version: Chrome Version 61.0.3163.79 (Official Build) (64-bit)
Second
- Python 2.7.12
- Django==1.11.5
- wagtail==1.11.1
- Browser version: Chrome Version 61.0.3163.79 (Official Build) (64-bit)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Sorting an array of objects by property values - Stack Overflow
How do I create a function to sort the objects by the price property in ascending or descending order using JavaScript only? javascript...
Read more >Built-in Types — Python 3.11.1 documentation
The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, ...
Read more >Restraining Orders - abuse_selfhelp - California Courts
These are orders telling the restrained person to move out from where the protected person lives and to take only clothing and personal...
Read more >What you Need to Know About Protective Orders
They are legal documents issued by a judge or magistrate to protect the health and safety of a person who is alleged to...
Read more >Opposing, Modifying, Dissolving, Or Appealing A Protection ...
You can file an opposition to the application or a motion asking the court to dissolve or modify the order, or you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey everybody. I was also having this issue, and while a fix on the actual CMS end will still be required at some point, this little hacky jQuery function should be enough to get you by. Just run it on page load on the admin side. This looks for any orderables that are missing that value=“” attr that the CMS does not generate when a min_num is set, and adds it.
IMHO - I like managing this on the serverside (option 1), reasoning is it is easier to test, more explicit in what we are providing to the clientside.