formtress-js 0.1.20 → 0.2.0

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.
Files changed (2) hide show
  1. package/README.md +24 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  Add the following script 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@0.1.9/dist/js/webflow.js"></script>
22
+ <script src="https://cdn.jsdelivr.net/npm/formtress-js@0.2.0/dist/js/webflow.js"></script>
23
23
  ```
24
24
 
25
25
  > Note: It's recommended to pin to a specific version in production for stability. Check the version badge above for the current release.
@@ -35,13 +35,30 @@ npm install formtress-js
35
35
  ### Webflow
36
36
 
37
37
  1. Copy the form ID from your [Formtress](https://app.formtress.com) account.
38
- 2. Add a `data-ft` attribute to your form and paste the form ID as the value.
39
- 3. That's it! The library will automatically handle the form submission, loading state, and error messages similar to how Webflow handles forms.
38
+ 2. In Webflow's form settings, set the form **Action** to your Formtress endpoint:
39
+ ```
40
+ https://app.formtress.com/api/f/{your-form-id}
41
+ ```
42
+ 3. That's it! The script enhances the form progressively:
43
+ - **Without JavaScript**: the form submits natively to Formtress, keeping it functional for all users.
44
+ - **With JavaScript**: the submission is intercepted and handled client-side, showing loading states and success/fail panels without a page reload — just like Webflow's native form behaviour.
40
45
 
41
- If you changed the default structure of the default error message, you will need to add a `data-ft-error` attribute to the text element that will display the error message.
46
+ If you changed the default structure of the error message element, add a `data-ft-error` attribute to the text element that should display the error message.
47
+
48
+ > **Note (v0.2.0 breaking change):** The previous `data-ft="your-form-id"` attribute is no longer used. Set the form `action` as described above instead.
42
49
 
43
50
  ### Core (any project)
44
51
 
52
+ Set the form `action` to your Formtress endpoint so it works without JavaScript:
53
+
54
+ ```html
55
+ <form id="my-form" action="https://app.formtress.com/api/f/your-form-id" method="POST">
56
+ <!-- your fields -->
57
+ </form>
58
+ ```
59
+
60
+ Then progressively enhance it with JavaScript:
61
+
45
62
  ```js
46
63
  import { submitForm } from 'formtress-js'
47
64
 
@@ -49,13 +66,13 @@ const form = document.querySelector('#my-form')
49
66
  form.addEventListener('submit', async (e) => {
50
67
  e.preventDefault()
51
68
  const result = await submitForm({
52
- formId: 'your-form-id',
69
+ url: form.action,
53
70
  data: new FormData(form),
54
71
  })
55
72
  if (result.ok) {
56
- console.log('Success!')
73
+ // show success state
57
74
  } else {
58
- console.error(result.message)
75
+ // show error state: result.message, result.status
59
76
  }
60
77
  })
61
78
  ```
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A tiny library for managing Formtress forms",
4
4
  "private": false,
5
5
  "license": "MIT",
6
- "version": "0.1.20",
6
+ "version": "0.2.0",
7
7
  "type": "module",
8
8
  "main": "dist/js/core.js",
9
9
  "module": "dist/js/core.js",