diff --git a/jsx/Modal.js b/jsx/Modal.js
index a068aa36ded..5e5ce1f6d30 100644
--- a/jsx/Modal.js
+++ b/jsx/Modal.js
@@ -132,11 +132,13 @@ class Modal extends Component {
const submitButton = () => {
if (onSubmit) {
+ const submit = () => onSubmit().then(() => this.props.onClose())
+ .catch(() => {});
return (
onSubmit().then(() => this.props.onClose())}
+ onUserInput={submit}
/>
);
@@ -169,7 +171,7 @@ class Modal extends Component {
Modal.propTypes = {
title: PropTypes.string,
- onSubmit: PropTypes.object,
+ onSubmit: PropTypes.func,
onClose: PropTypes.func.isRequired,
show: PropTypes.bool.isRequired,
throwWarning: PropTypes.bool,
diff --git a/modules/battery_manager/jsx/batteryManagerIndex.js b/modules/battery_manager/jsx/batteryManagerIndex.js
index b0f6b42365c..116eca0a09e 100644
--- a/modules/battery_manager/jsx/batteryManagerIndex.js
+++ b/modules/battery_manager/jsx/batteryManagerIndex.js
@@ -66,9 +66,9 @@ class BatteryManagerIndex extends Component {
return new Promise((resolve, reject) => {
return fetch(url, {credentials: 'same-origin', method: method})
.then((resp) => resp.json())
- .then((data) => this.setState({[state]: data}, resolve()))
+ .then((data) => this.setState({[state]: data}, resolve))
.catch((error) => {
- this.setState({error: true}, reject());
+ this.setState({error: true}, reject);
console.error(error);
});
});
@@ -211,7 +211,7 @@ class BatteryManagerIndex extends Component {
* Close the Form
*/
closeForm() {
- this.setState({add: false, edit: false, test: {}});
+ this.setState({add: false, edit: false, test: {}, errors: {}});
}
/**
@@ -254,10 +254,10 @@ class BatteryManagerIndex extends Component {
this.checkDuplicate(test)
.then((test) => this.validateTest(test))
.then((test) => this.postData(
- this.props.testEndpoint+test.id,
+ this.props.testEndpoint+(test.id || ''),
test,
- request)
- )
+ request
+ ))
.then(() => this.fetchData(this.props.testEndpoint, 'GET', 'tests'))
.then(() => resolve())
.catch((e) => reject(e));
@@ -470,18 +470,26 @@ class BatteryManagerIndex extends Component {
}
if (test.ageMinDays == null) {
errors.ageMinDays = 'This field is required';
+ } else if (test.ageMinDays < 0) {
+ errors.ageMinDays = 'This field must be 0 or greater';
}
if (test.ageMaxDays == null) {
errors.ageMaxDays = 'This field is required';
+ } else if (test.ageMaxDays < 0) {
+ errors.ageMaxDays = 'This field must be 0 or greater';
+ }
+ if (test.ageMinDays > test.ageMaxDays) {
+ errors.ageMinDays = 'Minimum age must be lesser than maximum age.';
+ errors.ageMaxDays = 'Maximum age must be greater than minimum age.';
}
if (test.stage == null) {
errors.stage = 'This field is required';
}
if (Object.entries(errors).length === 0) {
- this.setState({errors}, resolve(test));
+ this.setState({errors}, () => resolve(test));
} else {
- this.setState({errors}, reject());
+ this.setState({errors}, reject);
}
});
}
diff --git a/modules/battery_manager/php/testendpoint.class.inc b/modules/battery_manager/php/testendpoint.class.inc
index 4ad84c898b7..0d613bfb903 100644
--- a/modules/battery_manager/php/testendpoint.class.inc
+++ b/modules/battery_manager/php/testendpoint.class.inc
@@ -257,12 +257,27 @@ class TestEndpoint implements RequestHandlerInterface
if (!isset($test->row['ageMinDays'])) {
$errors[] = 'Minimum age is a required field.';
}
+ if (isset($test->row['ageMinDays']) && $test->row['ageMinDays'] < 0) {
+ $errors[] = 'Minimum age must be greater than 0.';
+ }
if (!isset($test->row['ageMaxDays'])) {
$errors[] = 'Maximum age is a required field.';
}
+ if (isset($test->row['ageMaxDays']) && $test->row['ageMaxDays'] < 0) {
+ $errors[] = 'Maximum age must be greater than 0.';
+ }
+ if ($test->row['ageMaxDays'] < $test->row['ageMinDays']) {
+ $errors[] = 'Maximum age must be greater than minimum age.';
+ }
if (!isset($test->row['stage'])) {
$errors[] = 'Stage is a required field.';
}
+ if (isset($test->row['instrumentOrder'])
+ && ($test->row['instrumentOrder'] > 127
+ || $test->row['instrumentOrder'] < -127)
+ ) {
+ $errors[] = 'Instrument order must be between -127 and 127';
+ }
return $errors;
}