I currently have a form
<%= form_for @emailer, :remote => true do |f| %>
<%= f.email_field :email, placeholder: "Email" %>
<%= f.submit "Send" %>
<% end %>
which I'm also calling from a JS popup
const {value: email} = await Swal.fire({
input: 'email',
.
.
.
})
if (email) {
form = $("#new_emailer")[0]
Rails.fire(form, 'submit');
}
It is working, but of course the form is not receiving any email, so the new emailer
is not created.
How can I submit the form by also sending the value of the email field inside the popup? Like
Rails.fire(form, email, 'submit');
EDIT WITH POSSIBLE SOLUTION:
I actually tried
if (email) {
form = $("#new_emailer")[0]
$('#emailer_email').val(email) // this is the email field of the form
Rails.fire(form, 'submit');
}
and it is working fine, but I'm not sure that's the best solution.