Commit 8bc32b69 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3272630 by RenatoG: Disable the add more attribute after the maximum limit is reached

parent fd9e6717
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

      removeAttributeItem();

      verify_to_disable_add_more_attribute_button();

      /**
       * This method will verify if there is validated items and should be displayed.
      */
@@ -61,6 +63,8 @@
      */
       function addAnotherAttributeItem() {

        console.log('Entrou no addAnotherAttributeItem');

        $(".block-class-add-another-attribute").unbind().click(function(event) {

          // Prevent Default to stop the normal behavior and avoid going to
@@ -73,6 +77,8 @@

          $('.hidden-attribute-field').first().removeClass('hidden-attribute-field');

          verify_to_disable_add_more_attribute_button();

        });

      }
@@ -102,6 +108,8 @@

        });

        verify_to_disable_add_more_attribute_button();

      }

      // On click to add another item, prevent default to stop going to another
@@ -198,6 +206,31 @@

      }

      /**
       * This method will verify if there is another attribute to be added.
      */
      function verify_to_disable_add_more_attribute_button() {

        var qty_attributes_per_block = $('.multiple-textfield-attribute').length;

        var qty_attributes_in_the_page = $('.displayed-attribute-field').length;

        // Verify if the qty items in the settings page is the same in the page.
        if (qty_attributes_per_block == qty_attributes_in_the_page) {

          // If yes disable the button to add more.
          $('.block-class-add-another-attribute').prop('disabled', true);

          return;

        }

        // If there is more, add the button to add more to be possible to add
        // new items in the page.
        $('.block-class-add-another-attribute').prop('disabled', false);

      }

      /**
       * This method will verify if is the last one that can't be removed.
       */