avalynx-form 1.0.2 → 1.0.4

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.de.md ADDED
@@ -0,0 +1,164 @@
1
+ # AvalynxForm
2
+
3
+ [![npm version](https://img.shields.io/npm/v/avalynx-form)](https://www.npmjs.com/package/avalynx-form)
4
+ [![npm downloads](https://img.shields.io/npm/dt/avalynx-form)](https://www.npmjs.com/package/avalynx-form)
5
+ [![jsDelivr](https://img.shields.io/jsdelivr/npm/hm/avalynx-form)](https://www.jsdelivr.com/package/npm/avalynx-form)
6
+ [![License](https://img.shields.io/npm/l/avalynx-form)](LICENSE)
7
+ [![Tests](https://github.com/avalynx/avalynx-form/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/avalynx/avalynx-form/actions/workflows/tests.yml)
8
+ [![codecov](https://codecov.io/gh/avalynx/avalynx-form/branch/main/graph/badge.svg)](https://codecov.io/gh/avalynx/avalynx-form)
9
+ [![GitHub stars](https://img.shields.io/github/stars/avalynx/avalynx-form?style=flat&logo=github)](https://github.com/avalynx/avalynx-form)
10
+
11
+ AvalynxForm ist eine leichtgewichtige, anpassbare Formular-Handling-Bibliothek für Webanwendungen. Basierend auf Bootstrap >=5.3 ohne jegliche Framework-Abhängigkeiten.
12
+
13
+ ## Funktionen
14
+
15
+ - **Formular-Handling**: Vereinfacht den Prozess der Erstellung und Verwaltung von Formularen in Ihren Webanwendungen.
16
+ - **Bootstrap-Integration**: Entwickelt für die nahtlose Integration mit Bootstrap >= 5.3.
17
+ - **Einfach zu bedienen**: Einfache API zur Erstellung und Verwaltung von Formularen in Ihren Webanwendungen.
18
+
19
+ ## Beispiel
20
+
21
+ Hier ist ein einfaches Beispiel für die Verwendung von AvalynxForm in Ihrem Projekt:
22
+
23
+ * [Übersicht](https://avalynx-form.jbs-newmedia.de/examples/index.html)
24
+ * [Formular](https://avalynx-form.jbs-newmedia.de/examples/form.html)
25
+ * [Formular mit langsamer Antwort](https://avalynx-form.jbs-newmedia.de/examples/form-slow-response.html)
26
+ * [Formular mit AvalynxSelect](https://avalynx-form.jbs-newmedia.de/examples/form-with-avalynx-select.html)
27
+
28
+ ## Installation
29
+
30
+ Um AvalynxForm in Ihrem Projekt zu verwenden, können Sie es direkt in Ihre HTML-Datei einbinden. Stellen Sie sicher, dass Sie Bootstrap 5.3 oder höher in Ihrem Projekt eingebunden haben, damit AvalynxForm korrekt funktioniert.
31
+
32
+ Zuerst Bootstrap einbinden:
33
+
34
+ ```html
35
+ <!-- Bootstrap -->
36
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/css/bootstrap.min.css" rel="stylesheet">
37
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/js/bootstrap.bundle.min.js"></script>
38
+ ```
39
+
40
+ Dann AvalynxForm einbinden:
41
+
42
+ ```html
43
+ <script src="pfad/zu/avalynx-form.js"></script>
44
+ ```
45
+
46
+ Ersetzen Sie `pfad/zu/avalynx-form.js` durch den tatsächlichen Pfad zur Datei in Ihrem Projekt.
47
+
48
+ ## Installation über jsDelivr ([Link](https://cdn.jsdelivr.net/npm/avalynx-form/))
49
+
50
+ AvalynxForm ist auch über [jsDelivr](https://www.jsdelivr.com/) verfügbar. Sie können es wie folgt in Ihr Projekt einbinden:
51
+
52
+ ```html
53
+ <script src="https://cdn.jsdelivr.net/npm/avalynx-form@1.0.4/dist/js/avalynx-form.js"></script>
54
+ ```
55
+
56
+ Stellen Sie sicher, dass Sie auch die JS/CSS-Dateien von Bootstrap in Ihr Projekt einbinden, um eine korrekte Anzeige von AvalynxForm zu gewährleisten.
57
+
58
+ ## Installation über NPM ([Link](https://www.npmjs.com/package/avalynx-form))
59
+
60
+ AvalynxForm ist auch als npm-Paket verfügbar. Sie können es mit dem folgenden Befehl zu Ihrem Projekt hinzufügen:
61
+
62
+ ```bash
63
+ npm install avalynx-form
64
+ ```
65
+
66
+ Nach der Installation können Sie AvalynxForm wie folgt in Ihre JavaScript-Datei importieren:
67
+
68
+ ```javascript
69
+ import { AvalynxForm } from 'avalynx-form';
70
+ ```
71
+
72
+ Stellen Sie sicher, dass Sie auch die JS/CSS-Dateien von Bootstrap in Ihr Projekt einbinden, um eine korrekte Anzeige von AvalynxForm zu gewährleisten.
73
+
74
+ ## Installation über Symfony AssetMapper
75
+
76
+ ```bash
77
+ php bin/console importmap:require avalynx-form
78
+ ```
79
+
80
+ Nach der Installation können Sie AvalynxForm wie folgt in Ihre JavaScript-Datei importieren:
81
+
82
+ ```javascript
83
+ import { AvalynxForm } from 'avalynx-form';
84
+ ```
85
+
86
+ Stellen Sie sicher, dass Sie auch die JS/CSS-Dateien von Bootstrap in Ihr Projekt einbinden, um eine korrekte Anzeige von AvalynxForm zu gewährleisten.
87
+
88
+ ## Installation über Symfony AssetComposer
89
+
90
+ Weitere Informationen zum Symfony AssetComposer Bundle finden Sie [hier](https://github.com/jbsnewmedia/asset-composer-bundle).
91
+
92
+ ```twig
93
+ {% do addAssetComposer('avalynx/avalynx-form/dist/js/avalynx-form.js') %}
94
+ ```
95
+
96
+ Stellen Sie sicher, dass Sie auch die JS/CSS-Dateien von Bootstrap in Ihr Projekt einbinden, um eine korrekte Anzeige von AvalynxForm zu gewährleisten.
97
+
98
+ ## Installation über Composer ([Link](https://packagist.org/packages/avalynx/avalynx-form))
99
+
100
+ AvalynxForm ist auch als Composer-Paket verfügbar. Sie können es mit dem folgenden Befehl zu Ihrem Projekt hinzufügen:
101
+
102
+ ```bash
103
+ composer require avalynx/avalynx-form
104
+ ```
105
+
106
+ Nach der Installation können Sie AvalynxForm wie folgt in Ihre HTML-Datei einbinden:
107
+
108
+ ```html
109
+ <script src="vendor/avalynx/avalynx-form/dist/js/avalynx-form.js"></script>
110
+ ```
111
+
112
+ Stellen Sie sicher, dass Sie auch die JS/CSS-Dateien von Bootstrap in Ihr Projekt einbinden, um eine korrekte Anzeige von AvalynxForm zu gewährleisten.
113
+
114
+ ## Verwendung
115
+
116
+ Um AvalynxForm in Ihrem Projekt zu verwenden, binden Sie die JavaScript-Datei von AvalynxForm in Ihr Projekt ein und initialisieren Sie die Klasse mit dem entsprechenden Selektor.
117
+
118
+ ```javascript
119
+ new AvalynxForm("myForm", {
120
+ apiParams: {
121
+ extraData1: 'wert1',
122
+ extraData2: 'wert2'
123
+ },
124
+ onSuccess: function(response) {
125
+ console.log('Formularübermittlung war erfolgreich:', response);
126
+ },
127
+ onError: function(response) {
128
+ console.error('Formularübermittlung fehlgeschlagen:', response);
129
+ }
130
+ });
131
+ ```
132
+
133
+ ## Optionen
134
+
135
+ AvalynxForm ermöglicht die folgenden Optionen zur Anpassung:
136
+
137
+ - `id`: (string) Die ID des Elements, an das das Formular angehängt werden soll.
138
+ - `options`: Ein Objekt, das die folgenden Schlüssel enthält:
139
+ - `apiParams`: (object) Zusätzliche Parameter, die mit den Formulardaten gesendet werden sollen (Standard: `{}`).
140
+ - `loader`: (object) Eine Instanz von AvalynxLoader, die als Loader für das Modal verwendet werden soll (Standard: `null`).
141
+ - `onSuccess`: (function) Eine Callback-Funktion, die ausgeführt wird, wenn die Formularübermittlung erfolgreich ist (Standard: `null`).
142
+ - `onError`: (function) Eine Callback-Funktion, die ausgeführt wird, wenn die Formularübermittlung fehlschlägt (Standard: `null`).
143
+ - `onBeforeSubmit`: (function) Eine Callback-Funktion, die vor der Formularübermittlung ausgeführt wird (Standard: `null`).
144
+ - `onAfterSubmit`: (function) Eine Callback-Funktion, die nach der Formularübermittlung ausgeführt wird (Standard: `null`).
145
+
146
+ ## Mitwirken
147
+
148
+ Beiträge sind willkommen! Wenn Sie einen Beitrag leisten möchten, erstellen Sie bitte einen Fork des Repositorys und senden Sie einen Pull-Request mit Ihren Änderungen oder Verbesserungen. Wir suchen nach Beiträgen in den folgenden Bereichen:
149
+
150
+ - Fehlerbehebungen
151
+ - Funktionserweiterungen
152
+ - Verbesserungen der Dokumentation
153
+
154
+ Bevor Sie Ihren Pull-Request absenden, stellen Sie bitte sicher, dass Ihre Änderungen gut dokumentiert sind und dem bestehenden Codierungsstil des Projekts entsprechen.
155
+
156
+ ## Lizenz
157
+
158
+ AvalynxForm ist quelloffene Software, die unter der [MIT-Lizenz](LICENSE) lizenziert ist.
159
+
160
+ ## Kontakt
161
+
162
+ Wenn Sie Fragen, Funktionswünsche oder Probleme haben, eröffnen Sie bitte ein Issue in unserem [GitHub-Repository](https://github.com/avalynx/avalynx-form/issues) oder senden Sie einen Pull-Request.
163
+
164
+ Vielen Dank, dass Sie AvalynxForm für Ihr Projekt in Betracht ziehen!
package/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # AvalynxForm
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/avalynx-form)](https://www.npmjs.com/package/avalynx-form)
4
+ [![npm downloads](https://img.shields.io/npm/dt/avalynx-form)](https://www.npmjs.com/package/avalynx-form)
5
+ [![jsDelivr](https://img.shields.io/jsdelivr/npm/hm/avalynx-form)](https://www.jsdelivr.com/package/npm/avalynx-form)
6
+ [![License](https://img.shields.io/npm/l/avalynx-form)](LICENSE)
7
+ [![Tests](https://github.com/avalynx/avalynx-form/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/avalynx/avalynx-form/actions/workflows/tests.yml)
8
+ [![codecov](https://codecov.io/gh/avalynx/avalynx-form/branch/main/graph/badge.svg)](https://codecov.io/gh/avalynx/avalynx-form)
9
+ [![GitHub stars](https://img.shields.io/github/stars/avalynx/avalynx-form?style=flat&logo=github)](https://github.com/avalynx/avalynx-form)
10
+
3
11
  AvalynxForm is a lightweight, customizable form handling library for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
4
12
 
5
13
  ## Features
@@ -42,7 +50,7 @@ Replace `path/to/avalynx-form.js` with the actual path to the file in your proje
42
50
  AvalynxForm is also available via [jsDelivr](https://www.jsdelivr.com/). You can include it in your project like this:
43
51
 
44
52
  ```html
45
- <script src="https://cdn.jsdelivr.net/npm/avalynx-form@1.0.2/dist/js/avalynx-form.js"></script>
53
+ <script src="https://cdn.jsdelivr.net/npm/avalynx-form@1.0.4/dist/js/avalynx-form.js"></script>
46
54
  ```
47
55
 
48
56
  Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxForm displays correctly.
@@ -108,7 +116,7 @@ Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxFo
108
116
  To use AvalynxForm in your project, include the AvalynxForm JavaScript file in your project and initialize the class with the appropriate selector.
109
117
 
110
118
  ```javascript
111
- new AvalynxForm("#myForm", {
119
+ new AvalynxForm("myForm", {
112
120
  apiParams: {
113
121
  extraData1: 'value1',
114
122
  extraData2: 'value2'
@@ -132,6 +140,8 @@ AvalynxForm allows the following options for customization:
132
140
  - `loader`: (object) An instance of AvalynxLoader to use as the loader for the modal (default: `null`).
133
141
  - `onSuccess`: (function) A callback function to be executed when the form submission is successful (default: `null`).
134
142
  - `onError`: (function) A callback function to be executed when the form submission fails (default: `null`).
143
+ - `onBeforeSubmit`: (function) A callback function to be executed before the form submission (default: `null`).
144
+ - `onAfterSubmit`: (function) A callback function to be executed after the form submission (default: `null`).
135
145
 
136
146
  ## Contributing
137
147
 
@@ -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.4
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
 
@@ -103,7 +119,7 @@ export class AvalynxForm {
103
119
  }
104
120
 
105
121
  if (response.redirect !== undefined) {
106
- window.location.href = response.redirect;
122
+ this.redirect(response.redirect);
107
123
  }
108
124
  } else {
109
125
  if (response.invalid !== undefined) {
@@ -179,4 +195,13 @@ export class AvalynxForm {
179
195
  this.form.appendChild(overlay);
180
196
  }
181
197
  }
182
- }
198
+
199
+ redirect(url) {
200
+ window.location.href = url;
201
+ }
202
+ }
203
+
204
+ /* istanbul ignore next */
205
+ if (typeof module !== 'undefined' && module.exports) {
206
+ module.exports = AvalynxForm;
207
+ }
@@ -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.4
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
 
@@ -101,7 +117,7 @@ class AvalynxForm {
101
117
  }
102
118
 
103
119
  if (response.redirect !== undefined) {
104
- window.location.href = response.redirect;
120
+ this.redirect(response.redirect);
105
121
  }
106
122
  } else {
107
123
  if (response.invalid !== undefined) {
@@ -177,8 +193,13 @@ class AvalynxForm {
177
193
  this.form.appendChild(overlay);
178
194
  }
179
195
  }
196
+
197
+ redirect(url) {
198
+ window.location.href = url;
199
+ }
180
200
  }
181
201
 
202
+ /* istanbul ignore next */
182
203
  if (typeof module !== 'undefined' && module.exports) {
183
204
  module.exports = AvalynxForm;
184
205
  }
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.4",
6
6
  "license": "MIT",
7
7
  "main": "dist/js/avalynx-form.js",
8
8
  "module": "dist/js/avalynx-form.esm.js",
@@ -42,12 +42,12 @@
42
42
  "bootstrap": ">=5.3"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/core": "^7",
46
- "@babel/preset-env": "^7",
47
- "babel-jest": "^29",
48
- "jest": "^29",
49
- "jest-environment-jsdom": "^29",
50
- "shelljs": "^0",
51
- "shx": "^0"
45
+ "@babel/core": "^7.29.0",
46
+ "@babel/preset-env": "^7.29.0",
47
+ "babel-jest": "^30.2.0",
48
+ "jest": "^30.2.0",
49
+ "jest-environment-jsdom": "^30.2.0",
50
+ "shelljs": "^0.10.0",
51
+ "shx": "^0.4.0"
52
52
  }
53
53
  }