From adbd4e22b10cb209d4c932db2d694b676efa7a0c Mon Sep 17 00:00:00 2001 From: Jure Triglav <juretriglav@gmail.com> Date: Tue, 23 Jun 2020 00:02:04 +0200 Subject: [PATCH] feat: fix validations in form builder forms --- .../src/components/atoms/Columns.js | 1 + .../src/components/FormTemplate.js | 23 +++++++++++-------- .../src/components/Submit.js | 11 +++++---- app/storage/forms/submit.json | 11 ++++++++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/components/component-xpub-formbuilder/src/components/atoms/Columns.js b/app/components/component-xpub-formbuilder/src/components/atoms/Columns.js index c550c32179..f2f4e3d858 100644 --- a/app/components/component-xpub-formbuilder/src/components/atoms/Columns.js +++ b/app/components/component-xpub-formbuilder/src/components/atoms/Columns.js @@ -6,6 +6,7 @@ const Columns = styled.div` grid-template-areas: 'form details'; grid-template-columns: minmax(200px, 70ch) minmax(200px, 60ch); justify-content: center; + overflow-y: scroll; ` const Form = styled.div` diff --git a/app/components/component-xpub-submit/src/components/FormTemplate.js b/app/components/component-xpub-submit/src/components/FormTemplate.js index 9440974a71..e979a9148a 100644 --- a/app/components/component-xpub-submit/src/components/FormTemplate.js +++ b/app/components/component-xpub-submit/src/components/FormTemplate.js @@ -104,18 +104,21 @@ const createMarkup = encodedHtml => ({ const composeValidate = (vld = [], valueField = {}) => value => { const validator = vld || [] + if (validator.length === 0) return undefined const errors = [] - validator.map(validatorFn => { - const error = - validatorFn === 'required' - ? validators[validatorFn](value) - : validators[validatorFn](valueField[validatorFn])(value) - if (error) { - errors.push(error) - } - return validatorFn - }) + validator + .map(v => v.value) + .map(validatorFn => { + const error = + validatorFn === 'required' + ? validators[validatorFn](value) + : validators[validatorFn](valueField[validatorFn])(value) + if (error) { + errors.push(error) + } + return validatorFn + }) return errors.length > 0 ? errors[0] : undefined } diff --git a/app/components/component-xpub-submit/src/components/Submit.js b/app/components/component-xpub-submit/src/components/Submit.js index b11a1578f2..824e222681 100644 --- a/app/components/component-xpub-submit/src/components/Submit.js +++ b/app/components/component-xpub-submit/src/components/Submit.js @@ -9,12 +9,13 @@ import { Columns, SubmissionVersion } from './atoms/Columns' import FormTemplate from './FormTemplate' const Wrapper = styled.div` - font-family: ${th('fontInterface')}; - line-height: 1.3; - margin: auto; - max-width: 60em; + overflow-y: scroll; + // font-family: ${th('fontInterface')}; + // line-height: 1.3; + // margin: auto; + // max-width: 60em; - overflow: ${({ confirming }) => confirming && 'hidden'}; + // overflow: ${({ confirming }) => confirming && 'hidden'}; ` const SubmittedVersionColumns = props => ( diff --git a/app/storage/forms/submit.json b/app/storage/forms/submit.json index dbcfd834ef..b5c51c7ea4 100644 --- a/app/storage/forms/submit.json +++ b/app/storage/forms/submit.json @@ -298,7 +298,16 @@ "id": "1591345370930", "component": "TextField", "name": "submission.humanMRIother", - "order": "24" + "order": "24", + "validate": [ + { + "value": "minChars", + "label": "minimum Characters" + } + ], + "validateValue": { + "minChars": "10" + } }, { "title": "Which processing packages did you use for your study?", -- GitLab