Are textareas not editable with enter key?

Are textareas not editable with enter key?

IsaacBenIsaacBen Posts: 35Questions: 8Answers: 4

I have a textarea field that on enter key inserts a line break, but I would like it to submit the edit instead. How can I do that?

This question has an accepted answers - jump to answer

Answers

  • IsaacBenIsaacBen Posts: 35Questions: 8Answers: 4

    This seems to do the job, but it's not as smooth and it doesn't show the loader icon. Hope there is a better way.

            $(".table").on("keydown", "textarea", function(e) {
                if(e.keyCode == 13) {
                    e.preventDefault();
                    editor.edit( $(this), null, null, false );
                    editor.set( 'description', $(this).val() );
                    editor.submit();
                }
            });
    
  • IsaacBenIsaacBen Posts: 35Questions: 8Answers: 4
    edited December 2016

    Okay, solved it. To make it function as a regular input inline edit I had to remove two lines from above.

            $(".table").on("keydown", "textarea", function(e) {
                if(e.keyCode == 13) {
                    e.preventDefault();
                    editor.submit();
                }
            });
    

    Works perfect now. Would still like to know if there is a builtin way to do this.

  • allanallan Posts: 63,831Questions: 1Answers: 10,518 Site admin
    Answer ✓

    The final option is the way to do this. There isn't a built in option for this since a return is typically perfectly valid in a textarea. Field's which don't need or allow a return would use a simple text input field. I realise that isn't always the case and if you have large amounts of text without a return you'd run into what you have, but typically that is what I have found to be the case.

    Editor 1.6 now has a new option in its field plug-ins to allow the plug-in to say if the return key should submit or not (canReturnSubmit). So perhaps the cleanest way would be to have a plug-in that uses a textarea but will use that option to allow return to submit.

    Regards,
    Allan

This discussion has been closed.