Skip to content

Commit

Permalink
Add javascripts folder with contact-form.js
Browse files Browse the repository at this point in the history
the contact-form.js will handle the contact form submissions, but for this js file to be
loaded in the main application, you need to include it like this:
<%= javascript_include_tag "wcc/contentful/app/application.js" %>
  • Loading branch information
rorJeremy committed Oct 29, 2018
1 parent 36fca2e commit 8698190
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$(window).load(function() {
$('[data-contact-form]').each((_, input) => {
const $form = $(input);

function handleResponse(status, responseJSON) {
if (responseJSON) {
alert(responseJSON.message);
} else {
alert('Sorry, something went wrong.');
}
$('input:visible, textarea', $form).val('');
}

$form.on('ajax:success', (event, data, status, xhr) => {
handleResponse(status, xhr.responseJSON);
});

$form.on('ajax:error', (event, xhr, status) => {
handleResponse(status, xhr.responseJSON);
});
});
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div class="contact-panel__content">
<!-- TODO: use route helper without needing to call directly on wcc_contentful_app -->
<%= form_tag wcc_contentful_app.contact_form_path, remote: true, data: { contact_us: 'yaddiyaddi' }, method: 'post' do %>
<%= form_tag wcc_contentful_app.contact_form_path, remote: true, data: { contact_form: 'yaddiyaddi' }, method: 'post' do %>
<input type="hidden" name="id" value="<%= section.id %>" />
<% section.fields&.each do |field| %>
<div class="field">
Expand Down

0 comments on commit 8698190

Please sign in to comment.