diff --git a/app/javascript/controllers/chatroom_subscription_controller.js b/app/javascript/controllers/chatroom_subscription_controller.js index 702a124..c85b340 100644 --- a/app/javascript/controllers/chatroom_subscription_controller.js +++ b/app/javascript/controllers/chatroom_subscription_controller.js @@ -3,6 +3,7 @@ import { createConsumer } from "@rails/actioncable" export default class extends Controller { static values = { chatroomId: Number } + static targets = ["messages", "form"] connect() { this.channel = createConsumer().subscriptions.create( @@ -15,4 +16,19 @@ export default class extends Controller { this.element.insertAdjacentHTML("beforeend", data) this.element.scrollTo(0, this.element.scrollHeight) } + + + + submitForm(e) { + e.preventDefault(); + // console.log(e.currentTarget); + try { + console.log("triggering form submit event"); + this.formTarget.submit(); + this.messagesTarget.scrollTo(0, this.messagesTarget.scrollHeight) + } catch (error) { + console.log(error.message); + } + + } } diff --git a/app/views/chatrooms/show.html.erb b/app/views/chatrooms/show.html.erb index e260b06..d1cb1c7 100644 --- a/app/views/chatrooms/show.html.erb +++ b/app/views/chatrooms/show.html.erb @@ -71,24 +71,24 @@ <% end %> -