Skip to content
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

Merged
merged 2 commits into from
Oct 9, 2015

Conversation

kaedroho
Copy link
Contributor

This pull request implements min_num and max_num parameters on InlinePanel (#669)

It requires a change to django-modelcluster (wagtail/django-modelcluster#37)

@salvadormrf
Copy link
Contributor

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");
        }
    };
...
}

@nimasmi
Copy link
Contributor

nimasmi commented Aug 13, 2015

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 n were used. My current way of implementing something that achieves the same is the exceedingly ugly:

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)

@gasman gasman modified the milestones: 1.2, 1.1 Aug 28, 2015
@gasman gasman merged commit d7953cc into wagtail:master Oct 9, 2015
gasman added a commit that referenced this pull request Oct 9, 2015
gasman added a commit that referenced this pull request Oct 9, 2015
@kaedroho kaedroho deleted the inline-panel-min-max branch December 1, 2015 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants