derafu-js 0.1.2 → 0.1.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/package.json +1 -1
- package/src/form/fields.js +46 -0
package/package.json
CHANGED
package/src/form/fields.js
CHANGED
|
@@ -84,6 +84,52 @@ FormFields.showPassword = function (button) {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Fills the password field next to the button with a randomly generated
|
|
89
|
+
* password.
|
|
90
|
+
*
|
|
91
|
+
* Relies on Utils.generatePassword() to create the value, so utils.js must
|
|
92
|
+
* be loaded before this file for this function to work.
|
|
93
|
+
*
|
|
94
|
+
* @param {HTMLElement} button - Button used to activate the function, located
|
|
95
|
+
* next to the password field.
|
|
96
|
+
* @param {number} [length] - Length of the generated password. Default is 12
|
|
97
|
+
* (see Utils.generatePassword()).
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
FormFields.generatePassword = function (button, length) {
|
|
101
|
+
'use strict';
|
|
102
|
+
if (!(button instanceof HTMLElement)) {
|
|
103
|
+
console.error(
|
|
104
|
+
'FormFields.generatePassword: The provided argument is not a valid HTML element.',
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
typeof Utils === 'undefined' ||
|
|
110
|
+
typeof Utils.generatePassword !== 'function'
|
|
111
|
+
) {
|
|
112
|
+
console.error(
|
|
113
|
+
'FormFields.generatePassword: Utils.generatePassword() is not available. Make sure utils.js is loaded before this file.',
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Try to find the related password field.
|
|
119
|
+
const input = button
|
|
120
|
+
.closest('.input-group')
|
|
121
|
+
.querySelector('input[type="password"], input[type="text"]');
|
|
122
|
+
|
|
123
|
+
if (!input) {
|
|
124
|
+
console.error('FormFields.generatePassword: Input not found.');
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Fill the field and notify listeners (e.g. validation) of the change.
|
|
129
|
+
input.value = Utils.generatePassword(length);
|
|
130
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
131
|
+
};
|
|
132
|
+
|
|
87
133
|
/**
|
|
88
134
|
* Allows editing the content of a text field in a larger dialog box.
|
|
89
135
|
* Useful for text fields with extensive content that would benefit from an
|