-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add javascripts folder with contact-form.js
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
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
wcc-contentful-app/app/assets/javascripts/wcc/contentful/app/application.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require_tree . |
22 changes: 22 additions & 0 deletions
22
wcc-contentful-app/app/assets/javascripts/wcc/contentful/app/contact-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters