diff --git a/src/components/dialog/new-project.js b/src/components/dialog/new-project.js index 6abc0c8..ae08024 100644 --- a/src/components/dialog/new-project.js +++ b/src/components/dialog/new-project.js @@ -43,21 +43,30 @@ class NewProjectDialog extends Component { } resetState() { - this.setState({ name: '', simulation: this.props.simulations[0]._id }); + this.setState({ + name: '', + simulation: this.props.simulations[0] != null ? this.props.simulations[0]._id : '' + }); } validateForm(target) { // check all controls var name = true; + var simulation = true; if (this.state.name === '') { name = false; } - this.valid = name; + if (this.state.simulation === '') { + simulation = false; + } + + this.valid = name && simulation; // return state to control if (target === 'name') return name ? "success" : "error"; + else if (target === 'simulation') return simulation ? "success" : "error"; } render() { @@ -69,7 +78,7 @@ class NewProjectDialog extends Component { this.handleChange(e)} /> - + Simulation this.handleChange(e)}> {this.props.simulations.map(simulation => ( diff --git a/src/components/dialog/new-simulation-model.js b/src/components/dialog/new-simulation-model.js index cb3ca63..e8cf8aa 100644 --- a/src/components/dialog/new-simulation-model.js +++ b/src/components/dialog/new-simulation-model.js @@ -72,28 +72,39 @@ class NewSimulationModelDialog extends Component { } resetState() { - this.setState({ name: '', simulator: this.props.simulators[0]._id, length: '1', mapping: [ { name: 'Signal', type: 'Type' } ] }); + this.setState({ + name: '', + simulator: this.props.simulators[0] != null ? this.props.simulators[0]._id : '', + length: '1', + mapping: [ { name: 'Signal', type: 'Type' } ] + }); } validateForm(target) { // check all controls var name = true; var length = true; + var simulator = true; if (this.state.name === '') { name = false; } + if (this.state.simulator === '') { + simulator = false; + } + // test if simulatorid is a number (in a string, not type of number) if (!/^\d+$/.test(this.state.length)) { length = false; } - this.valid = name && length; + this.valid = name && length && simulator; // return state to control if (target === 'name') return name ? "success" : "error"; else if (target === 'length') return length ? "success" : "error"; + else if (target === 'simulator') return simulator ? "success" : "error"; } render() {