DubFriend / jquery.repeater

Create a repeatable group of input elements
MIT License
392 stars 192 forks source link

Nested repeater setList not working when outer repeater has no fields other than the nested repeater #179

Open iThom96 opened 1 year ago

iThom96 commented 1 year ago

Example:

<form class="outer-repeater">
  <div data-repeater-list="outer-group" class="outer">
    <div data-repeater-item class="outer">

      <input data-repeater-delete type="button" value="Delete" class="outer" />

      <!-- When i remove this line the setList method no longer works -->
      <input type="hidden" name="text-input" value="A" class="outer" />

      <div class="inner-repeater">
        <div data-repeater-list="inner-group" class="inner">
          <div data-repeater-item class="inner">
            <input type="text" name="inner-text-input" value="B" class="inner" />
            <input data-repeater-delete type="button" value="Delete" class="inner" />
          </div>
        </div>

        <input data-repeater-create type="button" value="Add" class="inner" />

      </div>
    </div>
  </div>

  <input data-repeater-create type="button" value="Add" class="outer" />

</form>
var $outerRepeater = $(".outer-repeater").repeater({
  isFirstItemUndeletable: true,
  repeaters: [
    {
      selector: ".inner-repeater",
      isFirstItemUndeletable: true
    }
  ]
});

$outerRepeater.setList([
  {
    "inner-group": [{ "inner-text-input": "set-a" }]
  },
  {
    "inner-group": [{ "inner-text-input": "set-b" }]
  }
]);