update it
This commit is contained in:
parent
373880f6ba
commit
c1c0a40f7e
|
@ -129,8 +129,11 @@ class Form extends Component {
|
|||
schema: PropTypes.object,
|
||||
uiSchema: PropTypes.object,
|
||||
formData: PropTypes.object,
|
||||
isLoading: PropTypes.bool,
|
||||
disableSubmitButton: PropTypes.bool,
|
||||
valdate: PropTypes.func,
|
||||
onHide: PropTypes.func,
|
||||
onChange: PropTypes.func,
|
||||
onSubmit: PropTypes.func
|
||||
};
|
||||
|
||||
|
|
|
@ -155,10 +155,13 @@ const uiSchema = {
|
|||
class Edit extends Component {
|
||||
static propTypes = {
|
||||
visible: PropTypes.bool,
|
||||
title: PropTypes.string,
|
||||
action: PropTypes.string,
|
||||
formData: PropTypes.object,
|
||||
isLoading: PropTypes.bool,
|
||||
disableSubmitButton: PropTypes.bool,
|
||||
validate: PropTypes.func,
|
||||
onHide: PropTypes.func,
|
||||
onChange: PropTypes.func,
|
||||
onSubmit: PropTypes.func
|
||||
}
|
||||
|
||||
|
@ -168,10 +171,6 @@ class Edit extends Component {
|
|||
this.state = this.getStateFromProps(props);
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.setState(this.getStateFromProps(this.props));
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState(this.getStateFromProps(nextProps));
|
||||
}
|
||||
|
@ -212,38 +211,14 @@ class Edit extends Component {
|
|||
return state;
|
||||
}
|
||||
|
||||
validate = (formData, errors) => {
|
||||
if (formData && formData.pdn) {
|
||||
let apns = formData.pdn.map(pdn => { return pdn.apn } )
|
||||
let duplicates = {};
|
||||
for (let i = 0; i < apns.length; i++) {
|
||||
if (duplicates.hasOwnProperty(apns[i])) {
|
||||
duplicates[apns[i]].push(i);
|
||||
} else if (apns.lastIndexOf(apns[i]) !== i) {
|
||||
duplicates[apns[i]] = [i];
|
||||
}
|
||||
}
|
||||
|
||||
for (let key in duplicates) {
|
||||
duplicates[key].forEach(index =>
|
||||
errors.pdn[index].apn.addError(`'${key}' is duplicated`));
|
||||
}
|
||||
}
|
||||
|
||||
return this.props.validate(formData, errors);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
validate
|
||||
} = this;
|
||||
|
||||
const {
|
||||
visible,
|
||||
action,
|
||||
formData,
|
||||
isLoading,
|
||||
disableSubmitButton,
|
||||
validate,
|
||||
onHide,
|
||||
onChange,
|
||||
onSubmit
|
||||
|
@ -255,8 +230,8 @@ class Edit extends Component {
|
|||
title={(action === 'update') ? 'Edit Subscriber' : 'Create Subscriber'}
|
||||
schema={this.state.schema}
|
||||
uiSchema={this.state.uiSchema}
|
||||
isLoading={isLoading}
|
||||
formData={formData}
|
||||
isLoading={isLoading}
|
||||
disableSubmitButton={disableSubmitButton}
|
||||
validate={validate}
|
||||
onHide={onHide}
|
||||
|
|
|
@ -53,7 +53,6 @@ class Document extends Component {
|
|||
action: PropTypes.string,
|
||||
visible: PropTypes.bool,
|
||||
onHide: PropTypes.func,
|
||||
onSubmit: PropTypes.func,
|
||||
}
|
||||
|
||||
state = {
|
||||
|
@ -95,11 +94,29 @@ class Document extends Component {
|
|||
errors.imsi.addError(`'${imsi}' is duplicated`);
|
||||
}
|
||||
|
||||
if (formData.pdn) {
|
||||
let apns = formData.pdn.map(pdn => { return pdn.apn } )
|
||||
let duplicates = {};
|
||||
for (let i = 0; i < apns.length; i++) {
|
||||
if (duplicates.hasOwnProperty(apns[i])) {
|
||||
duplicates[apns[i]].push(i);
|
||||
} else if (apns.lastIndexOf(apns[i]) !== i) {
|
||||
duplicates[apns[i]] = [i];
|
||||
}
|
||||
}
|
||||
|
||||
for (let key in duplicates) {
|
||||
duplicates[key].forEach(index =>
|
||||
errors.pdn[index].apn.addError(`'${key}' is duplicated`));
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
handleChange = (formData, errors) => {
|
||||
let disableSubmitButton = (Object.keys(errors).length > 0);
|
||||
|
||||
// I think there is a bug in React or Jsonschema library
|
||||
// For workaround, I'll simply add 'formData' in setState
|
||||
this.setState({
|
||||
|
@ -109,7 +126,7 @@ class Document extends Component {
|
|||
}
|
||||
|
||||
handleSubmit = (formData) => {
|
||||
const { dispatch, action, onHide } = this.props;
|
||||
const { dispatch, action } = this.props;
|
||||
|
||||
this.setState({ disableValidation: true })
|
||||
|
||||
|
|
Loading…
Reference in New Issue