Jquery Repeater

Github:

https://github.com/DubFriend/jquery.repeater

Javascript

<script src="/plugins/jquery.repeater.min.js"></script>
<script>
var valid_products = '{!! $row->valid_products !!}';

$(document).ready(function(){
    $('#bt_submit').on('click', function(e){
        $('#iform').submit();
    });

    $('#iform').ajaxForm({
        dataType: 'json',
        beforeSubmit: function(arr, $form, options) {
            //console.log(arr);
            var new_arr = [];
            for(var i = 0; i < arr.length; i++){
              var name = arr[i];
              var pattern = /valid_products.+/;
              if(pattern.test(name) == false){
                new_arr.push(arr[i]);
              }
            }

            var values = $('.repeater').repeaterVal();
            var item = {
              name: 'valid_products', 
              value: values
            }
            new_arr.push(item);
            //console.log(values);
            //return false;

            return new_arr;
        },
        success: function(data, statusText, xhr, $form){
            //console.log(data);
            if(typeof data.status == 'undefined'){
                alert(data);
            }else if(data.status == 'fail'){
                alert(data.message);
            }else{
                //console.log(data);
                window.location.href = base_url + 'store/{{$controller}}';
            }
        },
        error: function(data){
            console.log(data);
            var res = data.responseJSON;
            show_response_error(res.errors);
        }
    });

    $('[name="discount_type"]').trigger('change');

    var $repeater = $('.repeater').repeater({
      isFirstItemUndeletable: true,
      defaultValues: {
          'discount': 100
      },
    });

    valid_products = $.parseJSON(valid_products);
    console.log(valid_products);
    $repeater.setList(valid_products);
});
</script>

HTML

<div class="form-group {{$field[0]}} repeater">
    <label for="{{$field[0]}}" class="col-md-3 control-label">
        {{$field[1]}}
        @if(isset($field[2]) && $field[2] == true)
        *
        @endif
    </label>
    <div class="col-md-9 filled">
        <input data-repeater-create type="button" value="Add"/>
        <table class="table table-hover dynamic_values">
            <thead>
                <tr>
                    <th>Item</th>
                    <th>Discount</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody data-repeater-list="{{$field[0]}}">
                <tr data-repeater-item>
                    <td>
                        <select class="form-control product-list" name="item_code">
                            <option value="">-- Select --</option>
                            @foreach($options as $key => $item)
                                @php
                                    $opt_value = $item->item_code;
                                    $display = $item->name . ' (' . $item->subtitle . ') : $' . $item->price;
                                @endphp
                                <option value="{{$opt_value}}">{{$display}}</option>
                            @endforeach
                        </select>
                    </td>
                    <td>
                        <input type="text" class="form-control" name="discount" value="100">
                    </td>
                    <td>
                        <input data-repeater-delete type="button" value="Delete"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>