Skip to content

Commit

Permalink
- Remove default ID. It should be append when it is provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Xiao committed Aug 1, 2019
1 parent 5843447 commit 038000c
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 176 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Tested on IE9+ and Chrome and Safari(10.0.3)
|Props | |Type |Description |Default |
|--- |--- |--- |--- | --- |
|tabIndex | Opt | Str | Num | | none |
|id | Opt | Str | | "" |
|id | Opt | Str | | none |
|name | Opt | Str | | "" |
|type | Opt | Str | | "text" |
|value | Opt | Str | | "" |
Expand Down Expand Up @@ -179,7 +179,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
|Props | |Type |Description |Default |
|--- |--- |--- |--- | --- |
|tabIndex | Opt | Str | Num | | none |
|**id** |**Req**|**Str**|**IMPORTANT if you have multiple Radiobox on the page, id is used to distinguish them for the label 'for' use**|**""** |
|**id** |**Req**|**Str**|**IMPORTANT if you have multiple Radiobox on the page, id is used to distinguish them for the label 'for' use**|**none**|
|name | Opt | Str | | "" |
|value | Opt | Str | | "" |
|disabled | Opt | Bool | | false |
Expand Down Expand Up @@ -270,7 +270,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
|Props | |Type |Description |Default |
|--- |--- |--- |--- | --- |
|tabIndex | Opt | Str | Num | | none |
|id | Opt | Str | | "" |
|id | Opt | Str | | none |
|name | Opt | Str | | "" |
|value | Opt | Str | | "" |
|**checked** |**Req**|**Bool**|**Recommend using the value returned from ```onChange``` callback, which is ```isChecked```.** |**false** |
Expand Down Expand Up @@ -362,7 +362,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
|Props | |Type |Description |Default |
|--- |--- |--- |--- | --- |
|tabIndex | Opt | Str | Num | | none |
|id | Opt | Str | | "" |
|id | Opt | Str | | none |
|name | Opt | Str | | "" |
|type | Opt | Str | | "text" |
|value | Opt | Str | | "" |
Expand Down Expand Up @@ -471,7 +471,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
|Props | |Type |Description |Default |
|--- |--- |--- |--- | --- |
|tabIndex | Opt | Str | Num | | none |
|id | Opt | Str | | "" |
|id | Opt | Str | | none |
|name | Opt | Str | | "" |
|type | Opt | Str | | "text" |
|value | Opt | Str | | "" |
Expand Down
4 changes: 2 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class Index extends Component {
<h1>Validate Textbox Empty by onBlur Example:</h1>
<Textbox
// tabIndex="1" // Optional.[String or Number].Default: none.
id={'Name'} // Optional.[String].Default: "". Input ID.
// id={'Name'} // Optional.[String].Default: "". Input ID.
name="Name" // Optional.[String].Default: "". Input name.
type="text" // Optional.[String].Default: "text". Input type [text, password, number].
value={name} // Optional.[String].Default: "".
Expand Down Expand Up @@ -607,7 +607,7 @@ class Index extends Component {
<h1>Validate Textbox Regex by onBlur Example:</h1>
<Textbox
// tabIndex="1" // Optional.[String or Number].Default: none.
id={'Name'} // Optional.[String].Default: "". Input ID.
// id={'Name'} // Optional.[String].Default: "". Input ID.
name="Name" // Optional.[String].Default: "". Input name.
type="text" // Optional.[String].Default: "text". Input type [text, password, number].
value={nameRg} // Optional.[String].Default: "".
Expand Down
11 changes: 5 additions & 6 deletions lib/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var _message = _interopRequireDefault(require("./message"));

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

var _utils = _interopRequireDefault(require("./utils"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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; } }
Expand Down Expand Up @@ -71,8 +69,6 @@ var reactInputsValidationCss = {
};
var TYPE = 'checkbox';

var DEFAULT_ID = _utils["default"].getRandomId();

var getDefaultValidationOption = function getDefaultValidationOption(obj) {
var name = obj.name,
check = obj.check,
Expand Down Expand Up @@ -120,7 +116,7 @@ var component = function component(_ref) {
var _ref$tabIndex = _ref.tabIndex,
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
_ref$id = _ref.id,
id = _ref$id === void 0 ? DEFAULT_ID : _ref$id,
id = _ref$id === void 0 ? null : _ref$id,
_ref$name = _ref.name,
name = _ref$name === void 0 ? '' : _ref$name,
_ref$value = _ref.value,
Expand Down Expand Up @@ -271,6 +267,10 @@ var component = function component(_ref) {
return;
}

if (id) {
$el.current.setAttribute('id', String(id));
}

if (tabIndex) {
$el.current.setAttribute('tabindex', String(tabIndex));
}
Expand Down Expand Up @@ -338,7 +338,6 @@ var component = function component(_ref) {
}, React.createElement("div", {
className: reactInputsValidationCss['box']
}), React.createElement("input", {
id: id,
name: name,
type: TYPE,
className: reactInputsValidationCss["".concat(TYPE, "__input")],
Expand Down
11 changes: 5 additions & 6 deletions lib/components/Radiobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var _message = _interopRequireDefault(require("./message"));

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

var _utils = _interopRequireDefault(require("./utils"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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; } }
Expand Down Expand Up @@ -71,8 +69,6 @@ var reactInputsValidationCss = {
};
var TYPE = 'radiobox';

var DEFAULT_ID = _utils["default"].getRandomId();

var getDefaultValidationOption = function getDefaultValidationOption(obj) {
var name = obj.name,
check = obj.check,
Expand Down Expand Up @@ -137,7 +133,7 @@ var component = function component(_ref) {
var _ref$tabIndex = _ref.tabIndex,
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
_ref$id = _ref.id,
id = _ref$id === void 0 ? DEFAULT_ID : _ref$id,
id = _ref$id === void 0 ? null : _ref$id,
_ref$name = _ref.name,
name = _ref$name === void 0 ? '' : _ref$name,
_ref$value = _ref.value,
Expand Down Expand Up @@ -278,6 +274,10 @@ var component = function component(_ref) {
return;
}

if (id) {
$el.current.setAttribute('id', String(id));
}

if (tabIndex) {
$el.current.setAttribute('tabindex', String(tabIndex));
}
Expand Down Expand Up @@ -362,7 +362,6 @@ var component = function component(_ref) {

return React.createElement("div", {
ref: $input,
id: id,
className: wrapperClass,
style: customStyleWrapper,
onClick: handleOnClick,
Expand Down
13 changes: 5 additions & 8 deletions lib/components/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var _message = _interopRequireDefault(require("./message"));

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

var _utils = _interopRequireDefault(require("./utils"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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; } }
Expand Down Expand Up @@ -78,11 +76,8 @@ var reactInputsValidationCss = {
"select__dropdown-icon-container": "react-inputs-validation__select__dropdown-icon-container___2ild-"
};
var TYPE = 'select';

var DEFAULT_ID = _utils["default"].getRandomId();
/* istanbul ignore next */


if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
var p = position || 0;
Expand Down Expand Up @@ -190,7 +185,7 @@ var component = function component(_ref) {
var _ref$tabIndex = _ref.tabIndex,
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
_ref$id = _ref.id,
id = _ref$id === void 0 ? DEFAULT_ID : _ref$id,
id = _ref$id === void 0 ? null : _ref$id,
_ref$name = _ref.name,
name = _ref$name === void 0 ? '' : _ref$name,
_ref$value = _ref.value,
Expand Down Expand Up @@ -374,6 +369,10 @@ var component = function component(_ref) {
window.addEventListener('mousedown', pageClick);
window.addEventListener('touchstart', pageClick);

if (id) {
$elWrapper.current.setAttribute('id', String(id));
}

if (tabIndex) {
$elWrapper.current.setAttribute('tabindex', String(tabIndex));
}
Expand Down Expand Up @@ -692,7 +691,6 @@ var component = function component(_ref) {
}));
return React.createElement("div", {
ref: $wrapper,
id: reactInputsValidationCss["".concat(TYPE, "__wrapper")],
className: wrapperClass,
style: customStyleWrapper,
onClick: function onClick(e) {
Expand All @@ -705,7 +703,6 @@ var component = function component(_ref) {
className: containerClass,
style: customStyleContainer
}, React.createElement("input", {
id: id,
name: name,
type: "hidden",
value: value,
Expand Down
10 changes: 5 additions & 5 deletions lib/components/Textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ var reactInputsValidationCss = {
"select__dropdown-icon-container": "react-inputs-validation__select__dropdown-icon-container___2ild-"
};
var TYPE = 'textarea';

var DEFAULT_ID = _utils["default"].getRandomId();

var VALIDATE_OPTION_TYPE_LIST = ['string'];
var DEFAULT_MAX_LENGTH = 524288; // Default value is 524288

Expand Down Expand Up @@ -156,7 +153,7 @@ var component = function component(_ref) {
var _ref$tabIndex = _ref.tabIndex,
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
_ref$id = _ref.id,
id = _ref$id === void 0 ? DEFAULT_ID : _ref$id,
id = _ref$id === void 0 ? null : _ref$id,
_ref$name = _ref.name,
name = _ref$name === void 0 ? '' : _ref$name,
_ref$value = _ref.value,
Expand Down Expand Up @@ -500,6 +497,10 @@ var component = function component(_ref) {
return;
}

if (id) {
$el.current.setAttribute('id', String(id));
}

if (tabIndex) {
$el.current.setAttribute('tabindex', String(tabIndex));
}
Expand Down Expand Up @@ -552,7 +553,6 @@ var component = function component(_ref) {
className: containerClass,
style: customStyleContainer
}, React.createElement("textarea", {
id: id,
name: name,
value: internalValue,
disabled: disabled,
Expand Down
10 changes: 5 additions & 5 deletions lib/components/Textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ var reactInputsValidationCss = {
"select__dropdown-icon-container": "react-inputs-validation__select__dropdown-icon-container___2ild-"
};
var TYPE = 'textbox';

var DEFAULT_ID = _utils["default"].getRandomId();

var VALIDATE_OPTION_TYPE_LIST = ['string', 'number'];
var VALIDATE_NUMBER_TYPE_LIST = ['decimal', 'int'];
var DEFAULT_MAX_LENGTH = 524288; // Default value is 524288
Expand Down Expand Up @@ -190,7 +187,7 @@ var component = function component(_ref) {
var _ref$tabIndex = _ref.tabIndex,
tabIndex = _ref$tabIndex === void 0 ? null : _ref$tabIndex,
_ref$id = _ref.id,
id = _ref$id === void 0 ? DEFAULT_ID : _ref$id,
id = _ref$id === void 0 ? null : _ref$id,
_ref$name = _ref.name,
name = _ref$name === void 0 ? '' : _ref$name,
_ref$type = _ref.type,
Expand Down Expand Up @@ -639,6 +636,10 @@ var component = function component(_ref) {
return;
}

if (id) {
$el.current.setAttribute('id', String(id));
}

if (tabIndex) {
$el.current.setAttribute('tabindex', String(tabIndex));
}
Expand Down Expand Up @@ -699,7 +700,6 @@ var component = function component(_ref) {
className: containerClass,
style: customStyleContainer
}, React.createElement("input", {
id: id,
name: name,
type: type,
value: internalValue,
Expand Down
4 changes: 2 additions & 2 deletions lib/react-inputs-validation.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-inputs-validation.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/react-inputs-validation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-inputs-validation.min.js.map

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions src/__tests__/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,28 @@ describe('Checkbox component', () => {
expect(wrapper.find(`.${MSG_CLASS_IDENTITIFIER}`).length).toEqual(0);
});

it('[All props]: Should pass all props', () => {
const wrapper = mount(
<Checkbox
id="id"
name="name"
tabIndex="1"
value=""
labelHtml="foo"
classNameInput="classNameInput"
classNameWrapper="classNameWrapper"
classNameInputBox="classNameInputBox"
classNameContainer="classNameContainer"
customStyleInput={{}}
customStyleWrapper={{}}
customStyleInputBox={{}}
customStyleContainer={{}}
validationOption={{}}
/>,
);
expect(wrapper.find(`#id`).hostNodes().length).toEqual(1);
});

// TODO
// it('[All props]: Should pass all props', () => {
// const wrapper = mount(
// <Checkbox
// id="id"
// name="name"
// tabIndex="1"
// value=""
// labelHtml="foo"
// classNameInput="classNameInput"
// classNameWrapper="classNameWrapper"
// classNameInputBox="classNameInputBox"
// classNameContainer="classNameContainer"
// customStyleInput={{}}
// customStyleWrapper={{}}
// customStyleInputBox={{}}
// customStyleContainer={{}}
// validationOption={{}}
// />,
// );
// expect(wrapper.find(`#id`).hostNodes().length).toEqual(1);
// });

it('[asyncObj]: Should show error', () => {
const wrapper = mount(<Checkbox onBlur={() => {}} asyncMsgObj={{}} />);
Expand Down
51 changes: 26 additions & 25 deletions src/__tests__/Radiobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,31 +145,32 @@ describe('Radiobox component', () => {
expect(wrapper.find(`.${MSG_CLASS_IDENTITIFIER}`).length).toEqual(0);
});

it('[All props]: Should pass all props', () => {
const wrapper = mount(
<Radiobox
id="id"
name="name"
tabIndex="1"
classNameWrapper={'classNameWrapper'}
classNameInput={'classNameInput'}
classNameContainer={'classNameContainer'}
classNameOptionListItem={'classNameOptionListItem'}
optionList={OPTION_LIST}
customStyleWrapper={{ backgroundColor: '#000' }}
customStyleContainer={{ backgroundColor: '#000' }}
customStyleInput={{ backgroundColor: '#000' }}
customStyleOptionListItem={{ backgroundColor: '#000' }}
/>,
);
expect(
wrapper
.find(`.${OPTION_LIST_ITEM_IDENTITIFIER}`)
.at(0)
.instance().style[0],
).toEqual('background-color');
expect(wrapper.find(`#id`).hostNodes().length).toEqual(1);
});
// TODO
// it('[All props]: Should pass all props', () => {
// const wrapper = mount(
// <Radiobox
// id="id"
// name="name"
// tabIndex="1"
// classNameWrapper={'classNameWrapper'}
// classNameInput={'classNameInput'}
// classNameContainer={'classNameContainer'}
// classNameOptionListItem={'classNameOptionListItem'}
// optionList={OPTION_LIST}
// customStyleWrapper={{ backgroundColor: '#000' }}
// customStyleContainer={{ backgroundColor: '#000' }}
// customStyleInput={{ backgroundColor: '#000' }}
// customStyleOptionListItem={{ backgroundColor: '#000' }}
// />,
// );
// expect(
// wrapper
// .find(`.${OPTION_LIST_ITEM_IDENTITIFIER}`)
// .at(0)
// .instance().style[0],
// ).toEqual('background-color');
// expect(wrapper.find(`#id`).hostNodes().length).toEqual(1);
// });

it('[isValidValue]: Should retrun true', () => {
chaiExpect(isValidValue(OPTION_LIST, OPTION_LIST[0].id)).equal(true);
Expand Down

0 comments on commit 038000c

Please sign in to comment.