formtress-js 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/js/webflow.js +1 -0
- package/package.json +1 -1
- package/src/{webflow/index.ts → webflow.ts} +4 -8
- package/vite.config.ts +15 -23
- package/dist/mjs/index.mjs +0 -1
- package/dist/umd/index.js +0 -1
- package/src/index.ts +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/formtress-js)
|
|
4
4
|
|
|
5
|
-
`formtress.js` is a tiny library that that submits your forms using javascript, and handles loading states, validation, and error messages.
|
|
5
|
+
`formtress.js` is a tiny library that that submits your forms using javascript, and handles loading states, validation, and error messages.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
- **Easy to use**: Just add a few attributes to your form and you're good to go.
|
|
11
11
|
- **Built-in validation**: Automatically validates your forms based on the forms you created in Formtress.
|
|
12
12
|
- **Error handling**: Automatically handles errors and displays them to the user.
|
|
13
|
-
- **Platform specific**:
|
|
13
|
+
- **Platform specific**: Built to work with Webflow's forms.
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
For Webflow, you can add the script to your project by adding the following code to your Webflow project settings before the closing `</body>` tag (change `latest` to the version you want to use):
|
|
20
20
|
|
|
21
21
|
```html
|
|
22
|
-
<script src="https://cdn.jsdelivr.net/npm/formtress-js@latest/dist/
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/formtress-js@latest/dist/umd/index.js"></script>
|
|
23
23
|
```
|
|
24
24
|
> Note: While using @latest is convenient, it's recommended to pin to a specific version in production for stability. Check the version badge above for the current release.
|
|
25
25
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function d(){document.querySelectorAll("form[data-ft]").forEach(r=>{const a=r.dataset.ft;if(!a)return;const s=r.closest(".w-form");if(!s)return;const t=s.querySelector(".w-button"),n=s.querySelector(".w-form-done"),e=s.querySelector(".w-form-fail");if(!t||!n||!e)return;const l=e.querySelector("[data-ft-error]")||e.firstChild;r.addEventListener("submit",async function(i){i.preventDefault(),i.stopPropagation(),e.style.display="none";const c=t.value;t.value=t.dataset.wait||"Please wait...";const u=new FormData(r);try{const o=await fetch(a,{method:"POST",body:u}),f=await o.text();t.value=c,o.ok?(r.style.display="none",n.style.display="block"):(console.error("Form submission failed:",o.status,o.statusText),l.textContent=f,e.style.display="block")}catch(o){console.error("Error submitting form:",o),l.textContent="An error occurred. Please try again later.",e.style.display="block",t.value=c}})})}typeof window<"u"&&d();
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const forms = document.querySelectorAll('form[data-ft
|
|
1
|
+
function webflow() {
|
|
2
|
+
const forms = document.querySelectorAll('form[data-ft]') as NodeListOf<HTMLFormElement>
|
|
3
3
|
|
|
4
4
|
forms.forEach((form) => {
|
|
5
5
|
const action = form.dataset.ft as string
|
|
@@ -11,13 +11,11 @@ export default function webflow() {
|
|
|
11
11
|
const fail = formWrapper.querySelector('.w-form-fail') as HTMLElement
|
|
12
12
|
if (!submitBtn || !success || !fail) return
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
if (!failText) {
|
|
16
|
-
failText = fail.firstChild as HTMLElement
|
|
17
|
-
}
|
|
14
|
+
const failText = fail.querySelector('[data-ft-error]') || fail.firstChild as HTMLElement
|
|
18
15
|
|
|
19
16
|
form.addEventListener('submit', async function (e: Event) {
|
|
20
17
|
e.preventDefault()
|
|
18
|
+
e.stopPropagation()
|
|
21
19
|
fail.style.display = 'none'
|
|
22
20
|
const initialButtonText = submitBtn.value
|
|
23
21
|
submitBtn.value = submitBtn.dataset.wait || 'Please wait...'
|
|
@@ -26,8 +24,6 @@ export default function webflow() {
|
|
|
26
24
|
const response = await fetch(action, {
|
|
27
25
|
method: 'POST',
|
|
28
26
|
body: formData,
|
|
29
|
-
mode: 'cors',
|
|
30
|
-
credentials: 'same-origin'
|
|
31
27
|
})
|
|
32
28
|
const message = await response.text()
|
|
33
29
|
submitBtn.value = initialButtonText
|
package/vite.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { globSync } from '
|
|
1
|
+
import { globSync } from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import { defineConfig } from "vite"
|
|
@@ -7,31 +7,23 @@ export default defineConfig({
|
|
|
7
7
|
base: "./",
|
|
8
8
|
build: {
|
|
9
9
|
rollupOptions: {
|
|
10
|
-
input:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// ),
|
|
10
|
+
input: Object.fromEntries(
|
|
11
|
+
globSync('src/**/*.ts').map(file => [
|
|
12
|
+
// This removes `src/` as well as the file extension from each
|
|
13
|
+
// file, so e.g. src/nested/foo.js becomes nested/foo
|
|
14
|
+
path.relative(
|
|
15
|
+
'src',
|
|
16
|
+
file.slice(0, file.length - path.extname(file).length)
|
|
17
|
+
),
|
|
18
|
+
// This expands the relative paths to absolute paths, so e.g.
|
|
19
|
+
// src/nested/foo becomes /project/src/nested/foo.js
|
|
20
|
+
fileURLToPath(new URL(file, import.meta.url))
|
|
21
|
+
])
|
|
22
|
+
),
|
|
24
23
|
output: [
|
|
25
24
|
{
|
|
26
|
-
dir: 'dist/
|
|
25
|
+
dir: 'dist/js',
|
|
27
26
|
format: 'es',
|
|
28
|
-
entryFileNames: '[name].mjs',
|
|
29
|
-
inlineDynamicImports: false
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
dir: 'dist/umd',
|
|
33
|
-
format: 'umd',
|
|
34
|
-
name: 'Formtress',
|
|
35
27
|
entryFileNames: '[name].js',
|
|
36
28
|
inlineDynamicImports: false
|
|
37
29
|
},
|
package/dist/mjs/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function d(){document.querySelectorAll('form[data-ft^="https://formtress"]').forEach(r=>{const n=r.dataset.ft;if(!n)return;const s=r.closest(".w-form");if(!s)return;const t=s.querySelector(".w-button"),l=s.querySelector(".w-form-done"),e=s.querySelector(".w-form-fail");if(!t||!l||!e)return;let a=e.querySelector("[data-ft-error]");a||(a=e.firstChild),r.addEventListener("submit",async function(c){c.preventDefault(),e.style.display="none";const i=t.value;t.value=t.dataset.wait||"Please wait...";const f=new FormData(r);try{const o=await fetch(n,{method:"POST",body:f,mode:"cors",credentials:"same-origin"}),u=await o.text();t.value=i,o.ok?(r.style.display="none",l.style.display="block"):(console.error("Form submission failed:",o.status,o.statusText),a.textContent=u,e.style.display="block")}catch(o){console.error("Error submitting form:",o),a.textContent="An error occurred. Please try again later.",e.style.display="block",t.value=i}})})}typeof window<"u"&&d();
|
package/dist/umd/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(n){typeof define=="function"&&define.amd?define(n):n()})(function(){"use strict";function n(){document.querySelectorAll('form[data-ft^="https://formtress"]').forEach(s=>{const i=s.dataset.ft;if(!i)return;const r=s.closest(".w-form");if(!r)return;const t=r.querySelector(".w-button"),l=r.querySelector(".w-form-done"),e=r.querySelector(".w-form-fail");if(!t||!l||!e)return;let a=e.querySelector("[data-ft-error]");a||(a=e.firstChild),s.addEventListener("submit",async function(f){f.preventDefault(),e.style.display="none";const c=t.value;t.value=t.dataset.wait||"Please wait...";const u=new FormData(s);try{const o=await fetch(i,{method:"POST",body:u,mode:"cors",credentials:"same-origin"}),d=await o.text();t.value=c,o.ok?(s.style.display="none",l.style.display="block"):(console.error("Form submission failed:",o.status,o.statusText),a.textContent=d,e.style.display="block")}catch(o){console.error("Error submitting form:",o),a.textContent="An error occurred. Please try again later.",e.style.display="block",t.value=c}})})}typeof window<"u"&&n()});
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as webflow } from './webflow'
|