Browse Source

Respect inline max forms for compactinline

Denis K 8 years ago
parent
commit
764e1a3981
1 changed files with 3 additions and 0 deletions
  1. 3 0
      jet/static/jet/js/src/features/compact-inline.js

+ 3 - 0
jet/static/jet/js/src/features/compact-inline.js

@@ -56,9 +56,12 @@ CompactInline.prototype = {
     },
     updateTotalForms: function($inline) {
         var $totalFormsInput = $inline.find('[name="' + this.prefix + '-TOTAL_FORMS"]');
+        var $maxFormsInput = $inline.find('[name="' + this.prefix + '-MAX_NUM_FORMS"]');
         var totalForms = parseInt($inline.find('.inline-related').length);
+        var maxForms = $maxFormsInput.val() ? parseInt($maxFormsInput.val()) : Infinity;
 
         $totalFormsInput.val(totalForms);
+        $inline.find('.add-row').toggle(maxForms >= totalForms);
     },
     addNavigationItem: function($inline, $inlineItem) {
         var $empty = $inline.find('.inline-navigation-item.empty');