Complete the code to connect a Stimulus controller named "hello" to an HTML element.
<div data-controller="[1]"> Hello, Stimulus! </div>
The data-controller attribute connects the HTML element to the Stimulus controller named "hello".
Complete the code to make a Turbo Frame with the ID "messages".
<turbo-frame id="[1]"> Loading messages... </turbo-frame>
The id attribute of the <turbo-frame> element should be "messages" to identify this frame.
Fix the error in the Stimulus controller method to log "Hello, Stimulus!" when connected.
import { Controller } from "@hotwired/stimulus" export default class extends Controller { connect() { console.[1]("Hello, Stimulus!") } }
console.print or other incorrect console methods.The correct method to output to the browser console is console.log().
Fill both blanks to create a Stimulus action that calls the "submit" method on form submission.
<form data-controller="form" data-action="[1]->[2]"> <input type="text" name="name"> <button type="submit">Send</button> </form>
The data-action attribute uses the format event->controller#method. Here, submit->form#submit means the submit event triggers the submit method on the form controller.
Fill all three blanks to create a Turbo Stream template that replaces the element with ID "notification" with new content.
<turbo-stream action="[1]" target="[2]"> <template> <div>[3]</div> </template> </turbo-stream>
The action attribute should be "replace" to replace the target element. The target is "notification" to specify the element ID. The template contains the new content to show.