@modernman00/shared-js-lib 1.2.30 → 1.2.32

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.
@@ -17,9 +17,9 @@ import { matchInput } from '../general.js';
17
17
  * @function setupPasswordChange
18
18
  * @param {Object} [config] - Configuration object for customizing behavior.
19
19
  * @param {string} [config.buttonId='button'] - ID of the submit button.
20
- * @param {string} [config.passwordId='password_id'] - ID of the password input field.
21
- * @param {string} [config.confirmId='confirm_password_id'] - ID of the confirm password input field.
22
- * @param {string} [config.showToggleId='showPassword_id'] - ID of the toggle button to show/hide password.
20
+ * @param {string} [config.passwordId='password'] - ID of the password input field.
21
+ * @param {string} [config.confirmId='confirm_password'] - ID of the confirm password input field.
22
+ * @param {string} [config.showToggleId='showPassword'] - ID of the toggle button to show/hide password.
23
23
  * @param {string} [config.errorId='confirm_password_error'] - ID of the element to display mismatch errors.
24
24
  * @param {string} [config.helpId='password_help'] - ID of the helper text element for password guidance.
25
25
  * @param {string} [config.route] - API endpoint for password change submission.
@@ -44,9 +44,9 @@ import { matchInput } from '../general.js';
44
44
  export const setupPasswordChange = ({
45
45
  formId = 'changePassword',
46
46
  buttonId = 'button',
47
- passwordId = 'password_id',
48
- confirmId = 'confirm_password_id',
49
- showToggleId = 'showPassword_id',
47
+ passwordId = 'password',
48
+ confirmId = 'confirm_password',
49
+ showToggleId = 'showPassword',
50
50
  errorId = 'confirm_password_error',
51
51
  helpId = 'password_help',
52
52
  route,
package/AcctMgt/code.js CHANGED
@@ -17,7 +17,7 @@ import { bindEvent } from '../Utility.js';
17
17
  * @example
18
18
  * createCodeSubmitHandler({
19
19
  * formId: 'codeForm',
20
- * inputId: 'code_id',
20
+ * inputId: 'code',
21
21
  * buttonId: 'button',
22
22
  * route: appTestRoutes.appTestCode,
23
23
  * redirect: appTestRoutes.appTestCodeRedirect
@@ -25,7 +25,7 @@ import { bindEvent } from '../Utility.js';
25
25
  */
26
26
  export function createCodeSubmitHandler({
27
27
  formId,
28
- inputId = 'code_id',
28
+ inputId = 'code',
29
29
  buttonId = 'button',
30
30
  route,
31
31
  redirect,
package/AcctMgt/forgot.js CHANGED
@@ -23,7 +23,7 @@ import {bindEvent } from '../Utility.js';
23
23
  * @example
24
24
  * createEmailSubmitHandler({
25
25
  * formId: 'forgotPassword',
26
- * inputId: 'email_id',
26
+ * inputId: 'email',
27
27
  * buttonId: 'button',
28
28
  * route: appTestRoutes.appTestForgot,
29
29
  * redirect: appTestRoutes.appTestForgotRedirect
@@ -31,7 +31,7 @@ import {bindEvent } from '../Utility.js';
31
31
  */
32
32
  export function forgotSubmitHandler({
33
33
  formId,
34
- inputId = 'email_id',
34
+ inputId = 'email',
35
35
  buttonId = 'button',
36
36
  route,
37
37
  redirect,
package/AcctMgt/login.js CHANGED
@@ -27,20 +27,20 @@ import { bindEvent, showPassword } from '../Utility.js';
27
27
  * @example
28
28
  * createAdminLoginHandler({
29
29
  * formId: 'managed',
30
- * emailId: 'email_id',
31
- * passwordId: 'password_id',
30
+ * emailId: 'email',
31
+ * passwordId: 'password',
32
32
  * buttonId: 'button',
33
- * showToggleId: 'showPassword_id',
33
+ * showToggleId: 'showPassword',
34
34
  * route: appTestRoutes.appTest,
35
35
  * redirect: appTestRoutes.redirect
36
36
  * });
37
37
  */
38
38
  export function createAdminLoginHandler({
39
39
  formId,
40
- emailId = 'email_id',
41
- passwordId = 'password_id',
40
+ emailId = 'email',
41
+ passwordId = 'password',
42
42
  buttonId = 'button',
43
- showToggleId = 'showPassword_id',
43
+ showToggleId = 'showPassword',
44
44
  route,
45
45
  redirect,
46
46
  theme = 'bootstrap',
package/FormHelper.js CHANGED
@@ -86,9 +86,9 @@ export default class FormHelper {
86
86
  *
87
87
  * @param {*} optionalFields ["spouseName", "spouseMobile", "fatherEmail"];
88
88
  * @param {*} typeMap Create a validation map if certain fields need special types (email, password, etc). const types = {
89
- email_id: "email",
90
- password_id: "password",
91
- custom_text_id: "general"
89
+ email: "email",
90
+ password: "password",
91
+ custom_text: "general"
92
92
  };
93
93
  * formHelper.massValidate(optional, types);
94
94
  */
@@ -101,22 +101,20 @@ export default class FormHelper {
101
101
 
102
102
  for (let input of this.data) {
103
103
  const { name, value, id, type, placeholder } = input;
104
-
105
104
 
106
105
 
107
106
  // Skip non-input elements
108
107
  if (
109
108
  ['submit', 'button', 'g-recaptcha-response', 'cancel'].includes(name) ||
110
- ['button', 'showPassword_id', 'token', 'g-recaptcha-response'].includes(id) ||
109
+ ['button', 'showPassword', 'token', 'g-recaptcha-response'].includes(id) ||
111
110
  type === 'button' ||
112
- id === 'checkbox_id'
111
+ id === 'checkbox'
113
112
  ) continue;
114
113
 
115
114
 
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`);
115
+
116
+
117
+ const errorEl = this.id(`${id}_error`);
120
118
  let val = value.trim();
121
119
 
122
120
  // Handle optional fields
@@ -127,8 +125,8 @@ export default class FormHelper {
127
125
 
128
126
  // Required field check
129
127
  if (val === '' || val === 'select') {
130
- if (errorEl) errorEl.innerHTML = `<li style="color:red;">${label} cannot be left empty.</li>`;
131
- this.error.push(`${label.toUpperCase()} cannot be left empty.`);
128
+ if (errorEl) errorEl.innerHTML = `<li style="color:red;">${id} cannot be left empty.</li>`;
129
+ this.error.push(`${id.toUpperCase()} cannot be left empty.`);
132
130
  continue;
133
131
  }
134
132
 
@@ -139,7 +137,7 @@ export default class FormHelper {
139
137
  );
140
138
 
141
139
  if (!this.matchRegex(val, validateType)) {
142
- const msg = `There is a problem with your entry for ${label.toUpperCase()}`;
140
+ const msg = `There is a problem with your entry for ${id.toUpperCase()}`;
143
141
  if (errorEl) errorEl.innerHTML = `<li style="color:red;">${msg}</li>`;
144
142
  this.error.push(msg);
145
143
  continue;
@@ -156,7 +154,7 @@ export default class FormHelper {
156
154
  emailVal() {
157
155
  const emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
158
156
  let msg = '<li style=color:\'red\';> Please enter a valid email</li>';
159
- const email = this.id('email_id').value;
157
+ const email = this.id('email').value;
160
158
  if (email.match(emailExp) === null) {
161
159
  this.id('email_error').innerHTML = msg;
162
160
  this.id('email_error').style.color = 'red';
@@ -189,11 +187,8 @@ export default class FormHelper {
189
187
  return;
190
188
  }
191
189
 
192
- // remove _id from id if it exists
193
- const cleanID = id.endsWith('_id') ? id.slice(0, -3) : id;
194
-
195
190
  // Add event listeners to clear errors
196
- const clearErrorHandler = () => clearErrorForElement(cleanID || name);
191
+ const clearErrorHandler = () => clearErrorForElement(id || name);
197
192
  if (value !== 'select') element.addEventListener('keyup', clearErrorHandler);
198
193
  element.addEventListener('change', clearErrorHandler);
199
194
  });
@@ -241,8 +236,8 @@ export default class FormHelper {
241
236
  * @param {string} second - the id of the second input
242
237
  */
243
238
  matchInput(first, second) {
244
- const firstInput = this.id(first + '_id');
245
- const secondInput = this.id(second + '_id');
239
+ const firstInput = this.id(first + '');
240
+ const secondInput = this.id(second + '');
246
241
  const error = this.id(`${second}_error`);
247
242
 
248
243
  const checkMatch = () => error.innerHTML = (firstInput.value !== secondInput.value) ? 'Your passwords do not match' : '';
package/Http.js CHANGED
@@ -44,7 +44,7 @@ export const postFormData = async (url, formId, redirect = null, css = null) =>
44
44
  let formEntries = new FormData(form);
45
45
 
46
46
  formEntries.delete('submit');
47
- formEntries.delete('checkbox_id');
47
+ formEntries.delete('checkbox');
48
48
 
49
49
  const options = {
50
50
  baseURL: '/', // Adjust to your API base URL
package/Utility.js CHANGED
@@ -8,13 +8,13 @@ import {autocomplete} from './theAutoComplete.js';
8
8
  * @throws {Error} if any element with id from the input array is not found or is empty
9
9
  */
10
10
  export const realTimeCheckLen = (input, maxi) => {
11
- const data = input.map(el => id(`${el}_id`));
11
+ const data = input.map(el => id(`${el}`));
12
12
  const errors = input.map(el => id(`${el}_error`));
13
13
  const helps = input.map(el => id(`${el}_help`));
14
14
 
15
15
  maxi.forEach((max, i) => {
16
16
  if (!data[i] || !errors[i] || !helps[i]) {
17
- throw new Error(`Element with ID '${input[i]}_id' not found or is empty`);
17
+ throw new Error(`Element with ID '${input[i]}' not found or is empty`);
18
18
  }
19
19
 
20
20
  data[i].maxLength = parseInt(max, 10) + 1;
@@ -40,7 +40,7 @@ describe('AcctMgt Handlers', () => {
40
40
 
41
41
  createCodeSubmitHandler({
42
42
  formId: 'codeForm',
43
- inputId: 'code_id',
43
+ inputId: 'code',
44
44
  buttonId: 'button',
45
45
  route: '/api/code',
46
46
  redirect: '/success',
@@ -55,19 +55,19 @@ describe('AcctMgt Handlers', () => {
55
55
  '/api/code',
56
56
  '/success',
57
57
  'bulma',
58
- { maxLength: { id: ['code_id'], max: [40] } }
58
+ { maxLength: { id: ['code'], max: [40] } }
59
59
  );
60
60
  });
61
61
 
62
62
  test('📧 forgotSubmitHandler submits email form correctly', () => {
63
63
  injectDOM([
64
64
  { id: 'button' },
65
- { tag: 'input', id: 'email_id', value: 'user@example.com' }
65
+ { tag: 'input', id: 'email', value: 'user@example.com' }
66
66
  ]);
67
67
 
68
68
  forgotSubmitHandler({
69
69
  formId: 'forgotPassword',
70
- inputId: 'email_id',
70
+ inputId: 'email',
71
71
  buttonId: 'button',
72
72
  route: '/api/forgot',
73
73
  redirect: '/reset',
@@ -82,23 +82,23 @@ describe('AcctMgt Handlers', () => {
82
82
  '/api/forgot',
83
83
  '/reset',
84
84
  'bulma',
85
- { maxLength: { id: ['email_id'], max: [50] } }
85
+ { maxLength: { id: ['email'], max: [50] } }
86
86
  );
87
87
  });
88
88
 
89
89
  test('🔐 createAdminLoginHandler sets attributes and submits login', () => {
90
90
  injectDOM([
91
91
  { id: 'button' },
92
- { id: 'showPassword_id' },
93
- { tag: 'input', id: 'password_id' }
92
+ { id: 'showPassword' },
93
+ { tag: 'input', id: 'password' }
94
94
  ]);
95
95
 
96
96
  createAdminLoginHandler({
97
97
  formId: 'managed',
98
- emailId: 'email_id',
99
- passwordId: 'password_id',
98
+ emailId: 'email',
99
+ passwordId: 'password',
100
100
  buttonId: 'button',
101
- showToggleId: 'showPassword_id',
101
+ showToggleId: 'showPassword',
102
102
  route: '/api/login',
103
103
  redirect: '/admin',
104
104
  theme: 'bootstrap',
@@ -106,37 +106,37 @@ describe('AcctMgt Handlers', () => {
106
106
  });
107
107
 
108
108
  document.getElementById('button').dispatchEvent(new Event('click'));
109
- document.getElementById('showPassword_id').dispatchEvent(new Event('click'));
109
+ document.getElementById('showPassword').dispatchEvent(new Event('click'));
110
110
 
111
111
  expect(loginSubmission).toHaveBeenCalledWith(
112
112
  'managed',
113
113
  '/api/login',
114
114
  '/admin',
115
115
  'bootstrap',
116
- { maxLength: { id: ['password_id', 'email_id'], max: [30, 50] } }
116
+ { maxLength: { id: ['password', 'email'], max: [30, 50] } }
117
117
  );
118
118
 
119
- expect(document.getElementById('password_id').getAttribute('autocomplete')).toBe('current-password');
120
- expect(showPassword).toHaveBeenCalledWith('password_id');
119
+ expect(document.getElementById('password').getAttribute('autocomplete')).toBe('current-password');
120
+ expect(showPassword).toHaveBeenCalledWith('password');
121
121
  });
122
122
 
123
123
  test('🔁 setupPasswordChange submits when passwords match', () => {
124
124
  injectDOM([
125
125
  { id: 'button' },
126
- { id: 'showPassword_id' },
127
- { tag: 'input', id: 'password_id', value: 'Secure123!' },
128
- { tag: 'input', id: 'confirm_password_id', value: 'Secure123!' },
126
+ { id: 'showPassword' },
127
+ { tag: 'input', id: 'password', value: 'Secure123!' },
128
+ { tag: 'input', id: 'confirm_password', value: 'Secure123!' },
129
129
  { tag: 'div', id: 'confirm_password_error' },
130
130
  { tag: 'div', id: 'password_help' }
131
131
  ]);
132
132
 
133
133
  setupPasswordChange({
134
134
  buttonId: 'button',
135
- passwordId: 'password_id',
136
- confirmId: 'confirm_password_id',
135
+ passwordId: 'password',
136
+ confirmId: 'confirm_password',
137
137
  errorId: 'confirm_password_error',
138
138
  helpId: 'password_help',
139
- showToggleId: 'showPassword_id',
139
+ showToggleId: 'showPassword',
140
140
  route: '/api/change-password',
141
141
  redirect: '/dashboard',
142
142
  theme: 'bulma',
@@ -150,7 +150,7 @@ describe('AcctMgt Handlers', () => {
150
150
  '/api/change-password',
151
151
  '/dashboard',
152
152
  'bulma',
153
- { maxLength: { id: ['password_id', 'confirm_password_id'], max: [50, 50] } }
153
+ { maxLength: { id: ['password', 'confirm_password'], max: [50, 50] } }
154
154
  );
155
155
  });
156
156
  });
@@ -1,3 +1,3 @@
1
1
  <?php
2
- define('APP_VERSION', 'v1.2.31');
2
+ define('APP_VERSION', 'v1.2.33');
3
3
 
package/index.js CHANGED
@@ -3,7 +3,7 @@ export * from './UtilityHtml.js';
3
3
  export * from './Utility.js';
4
4
  export * from './Loader.js';
5
5
  export * from './Cookie.js';
6
- export * from './FormHelper.js';
6
+ export { default as FormHelper } from './FormHelper';
7
7
  export * from './Loader.js';
8
8
  export * from './ShowResponse.js';
9
9
  export * from './DateTime.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernman00/shared-js-lib",
3
- "version": "1.2.30",
3
+ "version": "1.2.32",
4
4
  "description": "Reusable JS utilities for numerous js problems",
5
5
  "homepage": "https://github.com/modernman00/shared-js-lib#readme",
6
6
  "keywords": [