Extract a Value from an Stimulus Target Input

Share this video with your friends

Send Tweet

We will use data-target to tell our controller which input element we are getting our value from.

We need to declare static targets = ['name'] in our controller to tell which element we are referencing. We then reference the value in the input element with this.nameTarget.value.