10: Done Edit Todo

Update todo title after editing todo on done.

  1. Add doneEdit invocation to controller element by x-invocations directive.
  2. Add keyup event listener to <input> of edit todo by x-on:keyup directive. It calls doneEdit invocation on enter-key only.

<body>
  <section class="todoapp"


      focusTodo (_, payload, meta) {

      },
      doneEdit (_, payload, meta) {
        const todo = this.todos[payload.index]
        if (!todo) {
          return
        }

        if (this.editingTodoIndex === -1) {
          return
        }
        this.editingTodoIndex = -1

        const newTitle = meta._.$.value.trim()
        if (newTitle) {
          todo.title = newTitle
        }
      },
    }"
  ::>

    <section class="main">

      <ul class="todo-list"
        x-each="todo, index in todos"
      >


          <input class="edit"
            :value="todo.title"
            @change="doneEdit({index})"
          >
        </li>
      </ul>
    </section>

  </section>
</body>
</html>