diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index fed9ee3..fd8abf0 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -27,7 +27,8 @@ $weight-bold: 400; @import 'bulma/bulma'; @import "checkmark-icon"; -@import './demo'; +@import 'demo'; +@import 'highlight'; .field_with_errors input { border-color: $red; diff --git a/app/assets/stylesheets/highlight.css.scss b/app/assets/stylesheets/highlight.css.scss new file mode 100644 index 0000000..87e256f --- /dev/null +++ b/app/assets/stylesheets/highlight.css.scss @@ -0,0 +1,5 @@ +code.html .hljs-tag:first-child .hljs-attr, code.html .hljs-tag:first-child .hljs-string { + font-weight: bold; + font-size: 1.2em; +} + diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index 8b1495c..095ede0 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -39,6 +39,10 @@ class FormsController < ApplicationController end end + def setup + @form = current_user.forms.find_by!(token: params[:id]) + end + def form @form = Form.find_by!(token: params[:id]) end diff --git a/app/javascript/highlight.js b/app/javascript/highlight.js new file mode 100644 index 0000000..e48cb54 --- /dev/null +++ b/app/javascript/highlight.js @@ -0,0 +1,7 @@ +document.addEventListener("turbolinks:load", function () { + document.querySelectorAll('pre code').forEach(function (block) { + if (window.hljs) { + hljs.highlightBlock(block); + } + }); +}); diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 5aee77c..65acde0 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -13,6 +13,7 @@ require('tinyforms'); require('demo'); require('backend_typed'); require('tabs'); +require('highlight'); // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/tinyforms.js b/app/javascript/tinyforms.js index 2e6c4ce..f4b8601 100644 --- a/app/javascript/tinyforms.js +++ b/app/javascript/tinyforms.js @@ -40,9 +40,13 @@ window.tinyforms = { onSubmit: function(e) { e.preventDefault(); - return tinyforms.submitForm(this) + var form = this; + return tinyforms.submitForm(form) .then((response) => { this.dispatchEvent(new CustomEvent('tinyforms:submitted', {detail: { submission: response.submission, response: response }})); + if (form.dataset.tinyformsSubmitted && typeof window[form.dataset.tinyformsSubmitted] === 'function') { + window[form.dataset.tinyformsSubmitted](response.submission); + } }) .catch((response) => { this.dispatchEvent(new CustomEvent('tinyforms:error', {detail: { submission: response.submission, response: response }})); diff --git a/app/views/forms/_form_example.html.erb b/app/views/forms/_form_example.html.erb new file mode 100644 index 0000000..58844d6 --- /dev/null +++ b/app/views/forms/_form_example.html.erb @@ -0,0 +1,11 @@ +
diff --git a/app/views/forms/_form_example_js.html.erb b/app/views/forms/_form_example_js.html.erb new file mode 100644 index 0000000..6ef5a7d --- /dev/null +++ b/app/views/forms/_form_example_js.html.erb @@ -0,0 +1,11 @@ + diff --git a/app/views/forms/edit.html.erb b/app/views/forms/edit.html.erb index 4e04451..76ce773 100644 --- a/app/views/forms/edit.html.erb +++ b/app/views/forms/edit.html.erb @@ -1,14 +1,91 @@ -The URL where the user will be redirected after submission
+The name of the table in your Airtable base. Your Airtable can have multiple tables/sheets. Which one do you want to use?
+Your Airtable account API Key. You find this one on your Airtable account page.
+The application key of your Airtable document. You find this one on the API page of your Airtable base.
+<%= link_to form.title, form_url(form) %>
+ <%= submission_url(@form) %>
+
+ Please set your form action as in the example below. Make sure to use proper name
attributes.
+
+
+<%= html_escape_once render('form_example', form: @form) %>
+
+
+ + Learn more about our JavaScript library and our API in your help section. +
+
+<%= html_escape_once render('form_example_js', form: @form) %>
+
+
+
+
+
+