diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-11-10 22:02:48 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-11-10 22:02:48 +0100 |
| commit | d0e07a0fc06a83ed45dd7c491e1475e340aa564e (patch) | |
| tree | 0f70522dc6869afb0f467ff5375bc75e27ea8f44 /frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js | |
| parent | 2cf9276550b49bc102fb84a6debbbbac694d3e92 (diff) | |
Perform form validation in modals
This change updates the modal components to perform validation before
submitting the request.
Diffstat (limited to 'frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js')
| -rw-r--r-- | frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js index 67646e2c..3c6b8724 100644 --- a/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js +++ b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js @@ -5,15 +5,23 @@ import Modal from '../Modal' import { AVAILABLE_METRICS, METRIC_NAMES } from '../../../util/available-metrics' const NewPortfolioModalComponent = ({ show, callback }) => { + const form = useRef(null) const textInput = useRef(null) const repeatsInput = useRef(null) const metricCheckboxes = useRef({}) - const onSubmit = () => - callback(textInput.current.value, { - enabledMetrics: AVAILABLE_METRICS.filter((metric) => metricCheckboxes.current[metric].checked), - repeatsPerScenario: parseInt(repeatsInput.current.value), - }) + const onSubmit = () => { + if (form.current.reportValidity()) { + callback(textInput.current.value, { + enabledMetrics: AVAILABLE_METRICS.filter((metric) => metricCheckboxes.current[metric].checked), + repeatsPerScenario: parseInt(repeatsInput.current.value), + }) + + return true + } else { + return false + } + } const onCancel = () => callback(undefined) return ( @@ -23,6 +31,7 @@ const NewPortfolioModalComponent = ({ show, callback }) => { e.preventDefault() this.onSubmit() }} + innerRef={form} > <FormGroup> <Label for="name">Name</Label> |
