Question

I want to submit multiline text with Enter key pressing and I can see full-text before submitting it. I know there are two way to submit a form with textarea and input type=text, but both of them do not reach my requirement. Any help, please!

Note: Submit button is hidden

Form with textarea.It shows full-text but when I press Enter button, it creates a new line, not submit.

<form data-ng-submit="sendMessage(message)" >
     <textarea  data-ng-model="message" placeholder="Add your message"></textarea>
     <input style="display:none" type="submit" value="Submit">
</form>

Form with input type=text.Enter pressing to submit is ok, but It can not show multiline in text input field, so I can not see full-text

<form data-ng-submit="sendMessage(message)" >
     <input type="text"  data-ng-model="message" placeholder="Add your message"></textarea>
     <input style="display:none" type="submit" value="Submit">
</form>

No correct solution

OTHER TIPS

Textfields can't be multi-line, so that option is out. Intercepting a button press is complicated across browsers. jQuery provides a standardised interface into this data (if you're not using jQuery this will be difficult).

Extract from Form submitting when pressing enter in Textarea

$('#myTextArea').keydown(function(event) {
   if (event.keyCode == 13) {
      $(this.form).submit()
      return false;
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top