Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sameed_editz's avatar

how to do form submit on pressing enter and add new line on shift+enter in livewire

my blade file

i have tried this method but it says in console undefined function

and then i found livewire key modifiers , i tried them also

<form class="new-chat-form border-gradient" wire:submit.prevent="sendMessage" enctype="multipart/form-data">
            <textarea wire:model="inputMessage" id="message" rows="1" placeholder="Send a message..."
                wire:keydown.enter="sendMessage" wire:keydown.shift.enter="addNewLine" id="search-form"></textarea>
                <button type="submit" class="form-icon icon-send sendButton">
                    <i class="feather-send"></i>
                </button>
            </div>
        </form>

but while pressing enter form submits but when i click shift+enter then both function runs, sendMessage and addNewLine

how i can do form submit and add new line please help im stucked with this for a day

0 likes
3 replies
Nakov's avatar
Nakov
Best Answer
Level 73

This is what I tried:

<form class="new-chat-form border-gradient" wire:keydown.enter="sendMessage" enctype="multipart/form-data">
    <textarea wire:model="inputMessage" id="message" rows="1" placeholder="Send a message..."
              wire:keydown.shift.enter.stop="addNewLine"
              id="search-form"></textarea>
    <button type="submit" class="form-icon icon-send sendButton">
        <i class="feather-send"></i>
    </button>
</form>

and the function is just simply:

public function addNewLine()
{
   $this->inputMessage .= "";
}
sameed_editz's avatar

@Nakov thanks it worked, thank you soo much man. I love you brother (not in a gay way)

Please or to participate in this conversation.