DubFriend / jquery.repeater

Create a repeatable group of input elements
MIT License
388 stars 191 forks source link

Add Nested repeater dynamically #165

Open aniket-singh opened 2 years ago

aniket-singh commented 2 years ago

Hi,

I have a form where user can add multiple questions using repeater and inside the question the user can add multiple input option. As the question types are many so I'm fetching questions options through ajax and rendering it under the question.

Now when the question option are rendered through ajax i call, this is the html response

<div class="inner-repeater">
    <div data-repeater-list="inner-list">
        <div data-repeater-item>
            <div class="form-group">
                <label>Dropdown Answer</label>
                <input type="text" name="dropwdown[]"
                       placeholder="Member will be able to choose one option"
                       class="form-control question_answer">

            </div>
            <a href="javascript:void(0);"  data-repeater-delete>Remove Dropdown option</a>

        </div>
    </div>
    <div class="form-group">
        <div class="col p-0">
            <button class="btn btn-primary"  data-repeater-create type="button"><i
                    class="os-icon os-icon-folder-plus"></i>
                Add Dropdown option
            </button>
        </div>
    </div>

</div>
<script>
    $(".repeater-a").repeater({

        repeaters: [{
            // (Required)
            // Specify the jQuery selector for this nested repeater
            selector: '.inner-repeater'
        }],

    });
</script>

I append this code under the question. due to this solution plugin is being initialized again and then if i click on add button the whole question is repeated again with current dropdown options.

Screenshot 2022-07-11 at 3 22 51 PM

Is there a way to dynamically add the inner repeater and initialize it without effecting the main repeater