@modernman00/shared-js-lib 1.2.28 → 1.2.29

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.
@@ -29,7 +29,6 @@ export const loginSubmission = async (formId, loginURL, redirect, css = null, le
29
29
  return;
30
30
  }
31
31
 
32
-
33
32
  const formInputArr = Array.from(formInput.elements);
34
33
 
35
34
  const formData = new FormHelper(formInputArr);
@@ -48,7 +47,7 @@ export const loginSubmission = async (formId, loginURL, redirect, css = null, le
48
47
  showLoader();
49
48
  localStorage.setItem('redirect', redirect);
50
49
 
51
- await postFormData(loginURL, formId, redirect, css);
50
+ await postFormData(loginURL, formInput, redirect, css);
52
51
  } else {
53
52
 
54
53
  alert('The form cannot be submitted. Please check the errors');
package/FormHelper.js CHANGED
@@ -101,7 +101,7 @@ export default class FormHelper {
101
101
 
102
102
  for (let input of this.data) {
103
103
  const { name, value, id, type, placeholder } = input;
104
- const errorEl = this.id(`${name}_error`);
104
+
105
105
 
106
106
 
107
107
  // Skip non-input elements
@@ -109,16 +109,18 @@ export default class FormHelper {
109
109
  ['submit', 'button', 'g-recaptcha-response', 'cancel'].includes(name) ||
110
110
  ['button', 'showPassword_id', 'token', 'g-recaptcha-response'].includes(id) ||
111
111
  type === 'button' ||
112
- name === 'checkbox_id'
112
+ id === 'checkbox_id'
113
113
  ) continue;
114
114
 
115
115
 
116
-
117
- let label = name.replace(/_/g, ' '); // For readable error text
116
+ // remove _id from id if it exists to create a clean label
117
+ const cleanID = id.endsWith('_id') ? id.slice(0, -3) : id;
118
+ let label = cleanID.replace(/_/g, ' '); // For readable error text
119
+ const errorEl = this.id(`${cleanID}_error`);
118
120
  let val = value.trim();
119
121
 
120
122
  // Handle optional fields
121
- if (optionalFields.includes(name) && val === '') {
123
+ if (optionalFields.includes(id) && val === '') {
122
124
  input.value = 'Not Provided';
123
125
  continue;
124
126
  }
@@ -131,9 +133,9 @@ export default class FormHelper {
131
133
  }
132
134
 
133
135
  // Determine field type for regex
134
- let validateType = typeMap[name] || (
135
- name.toLowerCase().includes('email') ? 'email' :
136
- name.toLowerCase().includes('password') ? 'password' : 'general'
136
+ let validateType = typeMap[id] || (
137
+ id.toLowerCase().includes('email') ? 'email' :
138
+ id.toLowerCase().includes('password') ? 'password' : 'general'
137
139
  );
138
140
 
139
141
  if (!this.matchRegex(val, validateType)) {
@@ -187,8 +189,11 @@ export default class FormHelper {
187
189
  return;
188
190
  }
189
191
 
192
+ // remove _id from id if it exists
193
+ const cleanID = id.endsWith('_id') ? id.slice(0, -3) : id;
194
+
190
195
  // Add event listeners to clear errors
191
- const clearErrorHandler = () => clearErrorForElement(name);
196
+ const clearErrorHandler = () => clearErrorForElement(cleanID || name);
192
197
  if (value !== 'select') element.addEventListener('keyup', clearErrorHandler);
193
198
  element.addEventListener('change', clearErrorHandler);
194
199
  });
package/Http.js CHANGED
@@ -11,9 +11,9 @@ import { redirectAfterDelay, parseErrorResponse } from './general.js';
11
11
  * @param {string|null} css - The CSS framework to use for notification styling (e.g., 'W3css', 'bulma').
12
12
  NOTICE:::Make sure you set the notification id as the formId_notification
13
13
  */
14
- export const postFormData = async (url, formId, redirect = null, css = null) => {
14
+ export const postFormData = async (url, form, redirect = null, css = null) => {
15
15
 
16
- let notificationForm = `${formId}_notification`;
16
+ let notificationForm = `${form.id}_notification`;
17
17
  const notificationId = id(notificationForm);
18
18
 
19
19
 
@@ -34,11 +34,6 @@ export const postFormData = async (url, formId, redirect = null, css = null) =>
34
34
  // }
35
35
 
36
36
  // extract the form entries
37
- const form = id(formId);
38
-
39
- if (!form) {
40
- throw new Error('Form element not found');
41
- }
42
37
 
43
38
  let formEntries = new FormData(form);
44
39
 
@@ -1,3 +1,3 @@
1
1
  <?php
2
- define('APP_VERSION', 'v1.2.29');
2
+ define('APP_VERSION', 'v1.2.30');
3
3
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernman00/shared-js-lib",
3
- "version": "1.2.28",
3
+ "version": "1.2.29",
4
4
  "description": "Reusable JS utilities for numerous js problems",
5
5
  "homepage": "https://github.com/modernman00/shared-js-lib#readme",
6
6
  "keywords": [