As I work on submitting a form in JavaScript, the AJAX feature is functioning perfectly when manually submitting the form. However, there seems to be an issue when JavaScript attempts to submit it, resulting in a refresh.
The current code snippet I am working with looks like this:
:javascript
wistiaEmbed = Wistia.embed("#{@chapter.video_id}", {
autoPlay: true,
videoFoam: true,
playerColor: 'E68482'
});
wistiaEmbed.bind("end", function () {
document.getElementById('target').style.display = 'none';
document.getElementById('finished').style.display = 'block';
document.getElementById('new_chapter_completion').submit();
});
In addition, here is a preview of my form structure:
= form_for current_user.chapter_completions.build, remote: true, authenticity_token: true do |f|
= hidden_field_tag :chapter_id, @chapter.id
= f.submit
I have identified that the main problem lies within the .submit(); method being used. Can anyone guide me on what alternative approach I should consider?
Moreover, I am interested in having the form data submitted by JavaScript without the need for the form to be visibly present. Is there a way to achieve this while still maintaining the required #id?