avalynx-form 1.0.2 → 1.0.3

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 CHANGED
@@ -42,7 +42,7 @@ Replace `path/to/avalynx-form.js` with the actual path to the file in your proje
42
42
  AvalynxForm is also available via [jsDelivr](https://www.jsdelivr.com/). You can include it in your project like this:
43
43
 
44
44
  ```html
45
- <script src="https://cdn.jsdelivr.net/npm/avalynx-form@1.0.2/dist/js/avalynx-form.js"></script>
45
+ <script src="https://cdn.jsdelivr.net/npm/avalynx-form@1.0.3/dist/js/avalynx-form.js"></script>
46
46
  ```
47
47
 
48
48
  Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxForm displays correctly.
@@ -108,7 +108,7 @@ Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxFo
108
108
  To use AvalynxForm in your project, include the AvalynxForm JavaScript file in your project and initialize the class with the appropriate selector.
109
109
 
110
110
  ```javascript
111
- new AvalynxForm("#myForm", {
111
+ new AvalynxForm("myForm", {
112
112
  apiParams: {
113
113
  extraData1: 'value1',
114
114
  extraData2: 'value2'
@@ -132,6 +132,8 @@ AvalynxForm allows the following options for customization:
132
132
  - `loader`: (object) An instance of AvalynxLoader to use as the loader for the modal (default: `null`).
133
133
  - `onSuccess`: (function) A callback function to be executed when the form submission is successful (default: `null`).
134
134
  - `onError`: (function) A callback function to be executed when the form submission fails (default: `null`).
135
+ - `onBeforeSubmit`: (function) A callback function to be executed before the form submission (default: `null`).
136
+ - `onAfterSubmit`: (function) A callback function to be executed after the form submission (default: `null`).
135
137
 
136
138
  ## Contributing
137
139
 
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * AvalynxForm is a lightweight, customizable form handling library for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
5
5
  *
6
- * @version 1.0.2
6
+ * @version 1.0.3
7
7
  * @license MIT
8
- * @author https://github.com/avalynx/avalynx-datatable/graphs/contributors
8
+ * @author https://github.com/avalynx/avalynx-form/graphs/contributors
9
9
  * @website https://github.com/avalynx/
10
- * @repository https://github.com/avalynx/avalynx-datatable.git
11
- * @bugs https://github.com/avalynx/avalynx-datatable/issues
10
+ * @repository https://github.com/avalynx/avalynx-form.git
11
+ * @bugs https://github.com/avalynx/avalynx-form/issues
12
12
  *
13
13
  * @param {string} id - The ID of the element to attach the form to.
14
14
  * @param {object} options - An object containing the following keys:
@@ -16,6 +16,8 @@
16
16
  * @param {object} options.loader - An instance of AvalynxLoader to use as the loader for the modal (default: `null`).
17
17
  * @param {function} options.onSuccess - A callback function to be executed when the form submission is successful (default: `null`).
18
18
  * @param {function} options.onError - A callback function to be executed when the form submission fails (default: `null`).
19
+ * @param {function} options.onBeforeSubmit - A callback function to be executed before the form submission (default: `null`).
20
+ * @param {function} options.onAfterSubmit - A callback function to be executed after the form submission (default: `null`).
19
21
  *
20
22
  */
21
23
 
@@ -37,6 +39,8 @@ export class AvalynxForm {
37
39
  loader: null,
38
40
  onSuccess: null,
39
41
  onError: null,
42
+ onBeforeSubmit: null,
43
+ onAfterSubmit: null,
40
44
  ...options
41
45
  };
42
46
  this.init();
@@ -55,6 +59,12 @@ export class AvalynxForm {
55
59
  }
56
60
 
57
61
  async sendAjaxRequest() {
62
+ if (this.options.onBeforeSubmit) {
63
+ const result = this.options.onBeforeSubmit(this.form);
64
+ if (result === false) {
65
+ return;
66
+ }
67
+ }
58
68
  const action = this.form.action;
59
69
  const method = this.form.method.toUpperCase();
60
70
 
@@ -81,6 +91,9 @@ export class AvalynxForm {
81
91
  this.handleResponse(result);
82
92
  } catch (error) {
83
93
  console.error('Error during AJAX request:', error);
94
+ if (this.options.onError) {
95
+ this.options.onError(error);
96
+ }
84
97
  } finally {
85
98
  if (this.options.loader === null) {
86
99
  const overlay = document.getElementById(`${this.id}-overlay`);
@@ -90,6 +103,9 @@ export class AvalynxForm {
90
103
  } else {
91
104
  this.options.loader.load = false;
92
105
  }
106
+ if (this.options.onAfterSubmit) {
107
+ this.options.onAfterSubmit(this.form);
108
+ }
93
109
  }
94
110
  }
95
111
 
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * AvalynxForm is a lightweight, customizable form handling library for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
5
5
  *
6
- * @version 1.0.2
6
+ * @version 1.0.3
7
7
  * @license MIT
8
- * @author https://github.com/avalynx/avalynx-datatable/graphs/contributors
8
+ * @author https://github.com/avalynx/avalynx-form/graphs/contributors
9
9
  * @website https://github.com/avalynx/
10
- * @repository https://github.com/avalynx/avalynx-datatable.git
11
- * @bugs https://github.com/avalynx/avalynx-datatable/issues
10
+ * @repository https://github.com/avalynx/avalynx-form.git
11
+ * @bugs https://github.com/avalynx/avalynx-form/issues
12
12
  *
13
13
  * @param {string} id - The ID of the element to attach the form to.
14
14
  * @param {object} options - An object containing the following keys:
@@ -16,6 +16,8 @@
16
16
  * @param {object} options.loader - An instance of AvalynxLoader to use as the loader for the modal (default: `null`).
17
17
  * @param {function} options.onSuccess - A callback function to be executed when the form submission is successful (default: `null`).
18
18
  * @param {function} options.onError - A callback function to be executed when the form submission fails (default: `null`).
19
+ * @param {function} options.onBeforeSubmit - A callback function to be executed before the form submission (default: `null`).
20
+ * @param {function} options.onAfterSubmit - A callback function to be executed after the form submission (default: `null`).
19
21
  *
20
22
  */
21
23
 
@@ -35,6 +37,8 @@ class AvalynxForm {
35
37
  loader: null,
36
38
  onSuccess: null,
37
39
  onError: null,
40
+ onBeforeSubmit: null,
41
+ onAfterSubmit: null,
38
42
  ...options
39
43
  };
40
44
  this.init();
@@ -53,6 +57,12 @@ class AvalynxForm {
53
57
  }
54
58
 
55
59
  async sendAjaxRequest() {
60
+ if (this.options.onBeforeSubmit) {
61
+ const result = this.options.onBeforeSubmit(this.form);
62
+ if (result === false) {
63
+ return;
64
+ }
65
+ }
56
66
  const action = this.form.action;
57
67
  const method = this.form.method.toUpperCase();
58
68
 
@@ -79,6 +89,9 @@ class AvalynxForm {
79
89
  this.handleResponse(result);
80
90
  } catch (error) {
81
91
  console.error('Error during AJAX request:', error);
92
+ if (this.options.onError) {
93
+ this.options.onError(error);
94
+ }
82
95
  } finally {
83
96
  if (this.options.loader === null) {
84
97
  const overlay = document.getElementById(`${this.id}-overlay`);
@@ -88,6 +101,9 @@ class AvalynxForm {
88
101
  } else {
89
102
  this.options.loader.load = false;
90
103
  }
104
+ if (this.options.onAfterSubmit) {
105
+ this.options.onAfterSubmit(this.form);
106
+ }
91
107
  }
92
108
  }
93
109
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "avalynx-form",
3
3
  "title": "AvalynxForm",
4
4
  "description": "AvalynxForm is a lightweight, customizable form handling library for web applications. Based on Bootstrap >=5.3 without any framework dependencies.",
5
- "version": "1.0.2",
5
+ "version": "1.0.3",
6
6
  "license": "MIT",
7
7
  "main": "dist/js/avalynx-form.js",
8
8
  "module": "dist/js/avalynx-form.esm.js",