Skip to content

Commit ccee583

Browse files
authored
[Feature] Added handling of array of undefined validations (#802)
* Added handling of array of undefined validations * Fixed lint issues * Review changes
1 parent 98a9b2c commit ccee583

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/components/inputs/BaseInput.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Colors, Typography} from '../../style';
66
import {BaseComponent} from '../../commons';
77
import Validators from './Validators';
88

9-
109
const VALIDATORS = {
1110
REQUIRED: 'required',
1211
EMAIL: 'email',
@@ -90,7 +89,7 @@ export default class BaseInput extends BaseComponent {
9089
onFocus = (...args) => {
9190
_.invoke(this.props, 'onFocus', ...args);
9291
this.setState({focused: true});
93-
}
92+
};
9493

9594
onBlur = (...args) => {
9695
_.invoke(this.props, 'onBlur', ...args);
@@ -100,11 +99,11 @@ export default class BaseInput extends BaseComponent {
10099
if (validateOnBlur) {
101100
this.validate();
102101
}
103-
}
102+
};
104103

105104
onChange = (event) => {
106105
_.invoke(this.props, 'onChange', event);
107-
}
106+
};
108107

109108
onChangeText = (text) => {
110109
_.invoke(this.props, 'onChangeText', text);
@@ -114,7 +113,7 @@ export default class BaseInput extends BaseComponent {
114113
if (validateOnChange) {
115114
setImmediate(this.validate);
116115
}
117-
}
116+
};
118117

119118
/** Actions */
120119
getTypography() {
@@ -142,16 +141,17 @@ export default class BaseInput extends BaseComponent {
142141
this.input.clear();
143142
}
144143

145-
validate = (value = _.get(this, 'state.value'), dryRun) => { // 'input.state.value'
144+
validate = (value = _.get(this, 'state.value'), dryRun) => {
145+
// 'input.state.value'
146146
const {validate} = this.props;
147147
if (!validate) {
148148
return;
149149
}
150-
150+
151+
151152
let isValid = true;
152153
const inputValidators = _.isArray(validate) ? validate : [validate];
153154
let failingValidatorIndex;
154-
155155
// get validators
156156
for (let index = 0; index < inputValidators.length; index++) {
157157
const validator = inputValidators[index];
@@ -163,7 +163,7 @@ export default class BaseInput extends BaseComponent {
163163
}
164164

165165
// validate
166-
if (!validatorFunction(value)) {
166+
if (validatorFunction && !validatorFunction(value)) {
167167
isValid = false;
168168
failingValidatorIndex = index;
169169
break;

0 commit comments

Comments
 (0)