Skip to content

Commit 2608cf2

Browse files
author
Edward Xiao
committed
- Provide default random ID for each component.
1 parent b6270dd commit 2608cf2

17 files changed

+39
-18
lines changed

lib/components/Checkbox.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var _message = _interopRequireDefault(require("./message"));
1111

1212
var _const = require("./const");
1313

14+
var _utils = _interopRequireDefault(require("./utils"));
15+
1416
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
1517

1618
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
@@ -116,7 +118,7 @@ var component = function component(_ref) {
116118
var _ref$tabIndex = _ref.tabIndex,
117119
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
118120
_ref$id = _ref.id,
119-
id = _ref$id === void 0 ? '' : _ref$id,
121+
id = _ref$id === void 0 ? _utils["default"].getRandomId() : _ref$id,
120122
_ref$name = _ref.name,
121123
name = _ref$name === void 0 ? '' : _ref$name,
122124
_ref$value = _ref.value,

lib/components/Radiobox.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var _message = _interopRequireDefault(require("./message"));
1111

1212
var _const = require("./const");
1313

14+
var _utils = _interopRequireDefault(require("./utils"));
15+
1416
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
1517

1618
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
@@ -133,7 +135,7 @@ var component = function component(_ref) {
133135
var _ref$tabIndex = _ref.tabIndex,
134136
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
135137
_ref$id = _ref.id,
136-
id = _ref$id === void 0 ? '' : _ref$id,
138+
id = _ref$id === void 0 ? _utils["default"].getRandomId() : _ref$id,
137139
_ref$name = _ref.name,
138140
name = _ref$name === void 0 ? '' : _ref$name,
139141
_ref$value = _ref.value,

lib/components/Select.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var _message = _interopRequireDefault(require("./message"));
1111

1212
var _const = require("./const");
1313

14+
var _utils = _interopRequireDefault(require("./utils"));
15+
1416
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
1517

1618
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
@@ -185,7 +187,7 @@ var component = function component(_ref) {
185187
var _ref$tabIndex = _ref.tabIndex,
186188
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
187189
_ref$id = _ref.id,
188-
id = _ref$id === void 0 ? '' : _ref$id,
190+
id = _ref$id === void 0 ? _utils["default"].getRandomId() : _ref$id,
189191
_ref$name = _ref.name,
190192
name = _ref$name === void 0 ? '' : _ref$name,
191193
_ref$value = _ref.value,

lib/components/Textarea.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ var component = function component(_ref) {
153153
var _ref$tabIndex = _ref.tabIndex,
154154
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
155155
_ref$id = _ref.id,
156-
id = _ref$id === void 0 ? '' : _ref$id,
156+
id = _ref$id === void 0 ? _utils["default"].getRandomId() : _ref$id,
157157
_ref$name = _ref.name,
158158
name = _ref$name === void 0 ? '' : _ref$name,
159159
_ref$value = _ref.value,

lib/components/Textbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ var component = function component(_ref) {
187187
var _ref$tabIndex = _ref.tabIndex,
188188
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
189189
_ref$id = _ref.id,
190-
id = _ref$id === void 0 ? '' : _ref$id,
190+
id = _ref$id === void 0 ? _utils["default"].getRandomId() : _ref$id,
191191
_ref$name = _ref.name,
192192
name = _ref$name === void 0 ? '' : _ref$name,
193193
_ref$type = _ref.type,

lib/components/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ var toCamelCase = function toCamelCase(str) {
2020
};
2121
};
2222

23+
var getRandomId = function getRandomId() {
24+
return Math.random().toString(36).slice(-8);
25+
};
26+
2327
var utils = {
2428
camelize: camelize,
25-
toCamelCase: toCamelCase
29+
toCamelCase: toCamelCase,
30+
getRandomId: getRandomId
2631
};
2732
var _default = utils;
2833
exports["default"] = _default;

lib/react-inputs-validation.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-inputs-validation",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "React form input validation components",
55
"main": "index.js",
66
"repository": {

src/js/Inputs/Checkbox.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
const { useState, useEffect, useCallback, useRef, memo } = React;
33
import message from './message';
44
import { REACT_INPUTS_VALIDATION_CUSTOM_ERROR_MESSAGE_EXAMPLE, DEFAULT_LOCALE, WRAPPER_CLASS_IDENTITIFIER, MSG_CLASS_IDENTITIFIER, usePrevious } from './const';
5+
import utils from './utils';
56
import reactInputsValidationCss from './react-inputs-validation.css';
67
const TYPE = 'checkbox';
78
interface DefaultValidationOption {
@@ -78,7 +79,7 @@ interface Props {
7879
}
7980
const component: React.FC<Props> = ({
8081
tabIndex = null,
81-
id = '',
82+
id = utils.getRandomId(),
8283
name = '',
8384
value = '',
8485
checked = false,

src/js/Inputs/Radiobox.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
const { useState, useEffect, useCallback, useRef, memo } = React;
33
import message from './message';
44
import { REACT_INPUTS_VALIDATION_CUSTOM_ERROR_MESSAGE_EXAMPLE, DEFAULT_LOCALE, WRAPPER_CLASS_IDENTITIFIER, OPTION_LIST_ITEM_IDENTITIFIER, MSG_CLASS_IDENTITIFIER, usePrevious } from './const';
5+
import utils from './utils';
56
import reactInputsValidationCss from './react-inputs-validation.css';
67
const TYPE = 'radiobox';
78
interface DefaultValidationOption {
@@ -93,7 +94,7 @@ interface Props {
9394
}
9495
const component: React.FC<Props> = ({
9596
tabIndex = null,
96-
id = '',
97+
id = utils.getRandomId(),
9798
name = '',
9899
value = '',
99100
disabled = false,

src/js/Inputs/Select.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
const { useState, useEffect, useCallback, useRef, memo } = React;
33
import message from './message';
44
import { REACT_INPUTS_VALIDATION_CUSTOM_ERROR_MESSAGE_EXAMPLE, DEFAULT_LOCALE, WRAPPER_CLASS_IDENTITIFIER, CONTAINER_CLASS_IDENTITIFIER, MSG_CLASS_IDENTITIFIER, usePrevious } from './const';
5+
import utils from './utils';
56
import reactInputsValidationCss from './react-inputs-validation.css';
67
const TYPE = 'select';
78
/* istanbul ignore next */
@@ -135,7 +136,7 @@ let globalVariableCurrentFocus: any | null = null;
135136
let globalVariableTypingTimeout: any | null = null;
136137
const component: React.FC<Props> = ({
137138
tabIndex = null,
138-
id = '',
139+
id = utils.getRandomId(),
139140
name = '',
140141
value = '',
141142
disabled = false,

src/js/Inputs/Textarea.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ interface Props {
108108

109109
const component: React.FC<Props> = ({
110110
tabIndex = null,
111-
id = '',
111+
id = utils.getRandomId(),
112112
name = '',
113113
value = '',
114114
cols = DEFAULT_ROWS,

src/js/Inputs/Textbox.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const autoFormatNumber = (v: number | string, numberType: string) => {
137137
};
138138
const component: React.FC<Props> = ({
139139
tabIndex = null,
140-
id = '',
140+
id = utils.getRandomId(),
141141
name = '',
142142
type = 'text',
143143
value = '',

src/js/Inputs/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ interface Utils {
1414
[key: string]: Function;
1515
}
1616

17+
const getRandomId = () => {
18+
return Math.random()
19+
.toString(36)
20+
.slice(-8);
21+
};
22+
1723
const utils: Utils = {
1824
camelize,
1925
toCamelCase,
26+
getRandomId,
2027
};
2128
export default utils;

0 commit comments

Comments
 (0)