mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Update lib input
This commit is contained in:
parent
9255f8098e
commit
72bcfd23f7
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import { get, isEmpty, map, mapKeys, isObject, reject, includes } from 'lodash';
|
import { get, isEmpty, map, mapKeys, isObject, reject, includes } from 'lodash';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import DateTime from 'react-datetime';
|
import DateTime from 'react-datetime';
|
||||||
@ -67,37 +68,37 @@ class Input extends React.Component { // eslint-disable-line react/prefer-statel
|
|||||||
validate = (value) => {
|
validate = (value) => {
|
||||||
let errors = [];
|
let errors = [];
|
||||||
// handle i18n
|
// handle i18n
|
||||||
const requiredError = { id: 'error.validation.required' };
|
const requiredError = { id: `${this.props.pluginID}.error.validation.required` };
|
||||||
mapKeys(this.props.validations, (validationValue, validationKey) => {
|
mapKeys(this.props.validations, (validationValue, validationKey) => {
|
||||||
switch (validationKey) {
|
switch (validationKey) {
|
||||||
case 'max':
|
case 'max':
|
||||||
if (parseInt(value, 10) > validationValue) {
|
if (parseInt(value, 10) > validationValue) {
|
||||||
errors.push({ id: 'error.validation.max' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.max` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'maxLength':
|
case 'maxLength':
|
||||||
if (value.length > validationValue) {
|
if (value.length > validationValue) {
|
||||||
errors.push({ id: 'error.validation.maxLength' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.maxLength` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'min':
|
case 'min':
|
||||||
if (parseInt(value, 10) < validationValue) {
|
if (parseInt(value, 10) < validationValue) {
|
||||||
errors.push({ id: 'error.validation.min' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.min` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'minLength':
|
case 'minLength':
|
||||||
if (value.length < validationValue) {
|
if (value.length < validationValue) {
|
||||||
errors.push({ id: 'error.validation.minLength' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.minLength` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'required':
|
case 'required':
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
errors.push({ id: 'error.validation.required' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.required` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'regex':
|
case 'regex':
|
||||||
if (!new RegExp(validationValue).test(value)) {
|
if (!new RegExp(validationValue).test(value)) {
|
||||||
errors.push({ id: 'error.validation.regex' });
|
errors.push({ id: `${this.props.pluginID}.error.validation.regex` });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -367,36 +368,37 @@ class Input extends React.Component { // eslint-disable-line react/prefer-statel
|
|||||||
}
|
}
|
||||||
|
|
||||||
Input.propTypes = {
|
Input.propTypes = {
|
||||||
addon: React.PropTypes.oneOfType([
|
addon: PropTypes.oneOfType([
|
||||||
React.PropTypes.bool,
|
PropTypes.bool,
|
||||||
React.PropTypes.string,
|
PropTypes.string,
|
||||||
]),
|
]),
|
||||||
addRequiredInputDesign: React.PropTypes.bool,
|
addRequiredInputDesign: PropTypes.bool,
|
||||||
customBootstrapClass: React.PropTypes.string,
|
customBootstrapClass: PropTypes.string,
|
||||||
deactivateErrorHighlight: React.PropTypes.bool,
|
deactivateErrorHighlight: PropTypes.bool,
|
||||||
didCheckErrors: React.PropTypes.bool,
|
didCheckErrors: PropTypes.bool,
|
||||||
disabled: React.PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
errors: React.PropTypes.array,
|
errors: PropTypes.array,
|
||||||
handleBlur: React.PropTypes.oneOfType([
|
handleBlur: PropTypes.oneOfType([
|
||||||
React.PropTypes.func,
|
PropTypes.func,
|
||||||
React.PropTypes.bool,
|
PropTypes.bool,
|
||||||
]),
|
]),
|
||||||
handleChange: React.PropTypes.func.isRequired,
|
handleChange: PropTypes.func.isRequired,
|
||||||
handleFocus: React.PropTypes.func,
|
handleFocus: PropTypes.func,
|
||||||
inputDescription: React.PropTypes.string,
|
inputDescription: PropTypes.string,
|
||||||
label: React.PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
name: React.PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
noErrorsDescription: React.PropTypes.bool,
|
noErrorsDescription: PropTypes.bool,
|
||||||
placeholder: React.PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
selectOptions: React.PropTypes.array,
|
pluginID: PropTypes.string,
|
||||||
selectOptionsFetchSucceeded: React.PropTypes.bool,
|
selectOptions: PropTypes.array,
|
||||||
title: React.PropTypes.string,
|
selectOptionsFetchSucceeded: PropTypes.bool,
|
||||||
type: React.PropTypes.string.isRequired,
|
title: PropTypes.string,
|
||||||
validations: React.PropTypes.object.isRequired,
|
type: PropTypes.string.isRequired,
|
||||||
value: React.PropTypes.oneOfType([
|
validations: PropTypes.object.isRequired,
|
||||||
React.PropTypes.string,
|
value: PropTypes.oneOfType([
|
||||||
React.PropTypes.bool,
|
PropTypes.string,
|
||||||
React.PropTypes.number,
|
PropTypes.bool,
|
||||||
|
PropTypes.number,
|
||||||
]),
|
]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user