-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added min_num and max_num parameters to InlinePanel #1529
Conversation
8b0d34b
to
f4fffad
Compare
f4fffad
to
d7953cc
Compare
Can we disable the "add more" button on interface as well. (function() {
var panel = InlinePanel({
formsetPrefix: "id_{{ self.formset.prefix }}",
emptyChildFormPrefix: "{{ self.empty_child.form.prefix }}",
canOrder: {% if can_order %}true{% else %}false{% endif %},
maxForms: {{ self.formset.max_num }} // NEW
});
{% for child in self.children %}
panel.initChildControls("{{ child.form.prefix }}");
{% endfor %}
panel.setHasContent();
panel.updateMoveButtonDisabledStates();
panel.updateAddButtonState(); // NEW
})();
function InlinePanel(opts) {
....
self.updateAddButtonState = function() { // NEW
if (opts.maxForms) {
var currentforms = $('.inline-form', self.formsContainer).not('.deleted').length;
var addButton = $('#' + opts.formsetPrefix + '-ADD');
(currentforms >= opts.maxForms) ? addButton.addClass("disabled") : addButton.removeClass("disabled");
}
};
...
} |
I hereby notify of my appreciation and anticipation of this feature, in an attempt to alert you to the benefits it might have to others, and to convince you to prioritise it (otherwise known as 👍ing). This applies to a really common situation from front-enders' perspectives, where related items are listed horizontally, but a layout would break if more than related_item_1 = models.ForeignKey('wagtailcore.Page', null=True, related_name='+', blank=True, on_delete=models.SET_NULL)
related_item_2 = models.ForeignKey('wagtailcore.Page', null=True, related_name='+', blank=True, on_delete=models.SET_NULL)
related_item_3 = models.ForeignKey('wagtailcore.Page', null=True, related_name='+', blank=True, on_delete=models.SET_NULL)
related_item_4 = models.ForeignKey('wagtailcore.Page', null=True, related_name='+', blank=True, on_delete=models.SET_NULL) |
As suggested by @salvadormf in #1529 (comment)
This pull request implements
min_num
andmax_num
parameters onInlinePanel
(#669)It requires a change to
django-modelcluster
(wagtail/django-modelcluster#37)