V
V
Vladislav2019-09-13 12:23:36
Chats
Vladislav, 2019-09-13 12:23:36

How to make in textarea so that when ctrl + enter is pressed, it will wrap to a new line, enter will send a message to vue?

The essence of the problem is this, when you press enter, it transfers by default puts a line break, then performs some actions, I need to block the default transfer.
Here is an example code:

<textarea
      type="text"
      v-model="text"
      @keyup.enter.prevent="sendMessage"
      @keyup.ctrl.enter.prevent="newLine"
    ></textarea>

data() {
    return {
        text: ""
    }
},
methods: {
    sendMessage() {
      this.$emit("keyupCtrlEnter");
    },
    newLine(e) {
      let caret = e.target.selectionStart;
      e.target.setRangeText("\n", caret, caret, "end");
      this.text = e.target.value;
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-09-13
@umni4ak

Replace
with
@keydown.enter.prevent.exact

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question