Stimulus: Set the same value to a target defined multiple times on the page

Created on 10 Apr 2018  路  2Comments  路  Source: hotwired/stimulus

What I did:

  • defined a text input with data-target=jamming.solution
  • defined a hidden input with data-target=jamming.solution
  • do this.solutionTarget.value = 'foo'

What I expected:

  • text input to have value foo
  • hidden input to have value foo

What I got:

  • text' input to have valuefoo`
  • hidden input to have no value

On StimulusJS 1.0.1 (and a Rails 5.1 app)

Most helpful comment

I believe you have to use plural form this.solutionTargets and iterate over like:

this.solutionTargets.forEach( (elem) => { elem.value = 'foo' } )

All 2 comments

I believe you have to use plural form this.solutionTargets and iterate over like:

this.solutionTargets.forEach( (elem) => { elem.value = 'foo' } )

@skyksandr is correct (thanks!)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joeybeninghove picture joeybeninghove  路  4Comments

saneef picture saneef  路  4Comments

pherris picture pherris  路  3Comments

paulozoom picture paulozoom  路  4Comments

ngan picture ngan  路  3Comments