I’m trying to use Stimulus to add additional email fields to an invite list.
The code looks like this:
import { Controller } from "stimulus"
export default class extends Controller
addFields: ->
$('.invite-list').append '<input type="email" name="invite[email][]" id="email" value="" placeholder="Email address" class="form-control">'
And the HTML like this:
<div class="col" data-controller='invites'>
<a href="#" data-action="invites#addFields">add another</a>
</div>
It appears to work, but the added field immediately disappears after it appears. I am using Turbolinks, but I’m not submitting the form or anything, so I’m not sure why it would be refreshing the screen.
This gif may help explain. I try several times to add the field.