0

I can't seem to understand why I can't spam click my "create board" button and keep creating boards when I add a board the new empty board dict should be prepended to the front of the array but only one board will show up then no more..Thanks for the help!!!

<div id="target"></div>

<script id="template" type="text/ractive">


<button class="btn btn-primary" on-click="add_board"><i class="fa fa-plus"></i>  Board</button>
<br><br>

editing: {% editing %}


{% #board_list:title %}
    {% title %}
{% /board_list %}


<div class="board_list">
    {% #board_list:name %}
        <div class="board">
              {% #if editing %}
                <textarea id="editarea" on-blur="editdone" data-areaid="3" value="{% text %}"></textarea>
              {% else %}
                <div on-click="startedit"><p>{% text %}</p></div>
              {% /if %}
        </div>
    {% /board_list %}
</div>

</script>



<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>



<script>
$(function() {
  // Ractive object
  var MAIN = new Ractive({
    el: '#target',
    template: '#template',
    delimiters: ['{%', '%}'],
    tripleDelimiters: ['{%%', '%%}'],
    data: {
        editing: false,
        board_id: -1,
        text: "Edit Me",
        board_list: [],
        loading: false
    },
  });









MAIN.on("add_board", function() {
    board_list = MAIN.get('board_list');
    alert(board_list);
    var empty_board = {title: ''};
    board_list.splice(0, 1, empty_board);
    MAIN.set('board_list', board_list);
});


MAIN.on("startedit", function() {
MAIN.set("editing", true);
$("#editarea").focus();
});

MAIN.on("editdone", function() {
  MAIN.set("editing", false);
  var text = MAIN.get("text");
  alert(text);
  if (text.trim().length > 0) {
      //update_board()
      alert('not empty');
  }
  else {
      //delete_board()
      alert('empty');
  }
});
ajanakos
  • 99
  • 1
  • 9

1 Answers1

1

The second argument in splice is the number of elements to remove, you currently have it set to remove 1. If you change it to 0 then it will add more.

board_list.splice(0, 0, empty_board);

https://jsfiddle.net/6qz84476/

Victoria French
  • 756
  • 5
  • 10