Support

Account

Home Forums Add-ons Repeater Field Change class of element depending on amount of Repeater Field items Reply To: Change class of element depending on amount of Repeater Field items

  • You’ve got more there than you need and your additional ifs are complicating it.

    
          if ($row_count) {
            $size = (int)12/$row_count;
          }
    

    This calculates the width of the row

    if there is 1 row the result is 12 (col-12)
    if there is 2 rows the result is 6 (col-6)
    3 result 4 (col-4)
    4 result 3 (col-3)
    5 result 2 (actually 2.4 rounded to int) (col-2)
    6 result 2 (col-2)

    The only thing I did here was to add

    
    if ($size < 2) {
      //force minimum of col-lg-2
      $size = 2;
    }
    

    assuming you did not want to have a column smaller than that.