From 07081006b3f6e30b5635590fc6281138127bcef2 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Fri, 8 Sep 2023 10:00:42 +0200 Subject: [PATCH] fix: temporary validation --- .../AddModelDialog/AddModelDialog.tsx | 72 +++++++++---------- src/features/ModelMetadata/ModelMetadata.tsx | 6 +- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/features/AddModelDialog/AddModelDialog.tsx b/src/features/AddModelDialog/AddModelDialog.tsx index 6d9db7f9..9189d2c7 100644 --- a/src/features/AddModelDialog/AddModelDialog.tsx +++ b/src/features/AddModelDialog/AddModelDialog.tsx @@ -31,52 +31,48 @@ export const AddModelDialog = ({ }>({ field: false, formation: false }) const [metadata, setMetadata] = useState>() - // const [description, setDescription] = useState() - // const [field, setField] = useState() - // const [zone, setZone] = useState() - // const [formation, setFormation] = useState() - // const [analogue, setAnalogue] = useState() - // const [fieldError, setFieldError] = useState(false) - // const [formationError, setFormationError] = useState(false) - function toggleINIFileContent() { setFileDisplay(!isFileDisplay) } const INIFileContent = () =>

Not implemented yet...

- const validateInput = (values: string[] | undefined, target: string) => { - // const value = e.selectedItems - // console.log('Kjører: Value => ' + values + ' target => ' + target) - - values === undefined || !typeof Object - ? setValidationError({ ...validationError, [target]: true }) - : setValidationError({ ...validationError, [target]: false }) - // onChange(metadata) + const validateInput = ( + // input: { values: string[] | undefined; target: string }[] + input: { [target: string]: string[] | undefined } + ) => { + Object.entries(input).map(([target, value]) => + setValidationError({ ...validationError, [target]: value !== undefined }) + ) + // input.forEach((input) => { + // console.log('Kjører: ' + input.target) + // if (!input.values) + // setValidationError({ ...validationError, [input.target]: true }) + // + // if (input.values === undefined) { + // setValidationError({ ...validationError, [input.target]: true }) + // console.log('Undefined Error') + // console.log(validationError) + // } else if (input.values.length === 0) { + // setValidationError({ ...validationError, [input.target]: true }) + // console.log('Length 0 Error') + // console.log(validationError) + // } else { + // setValidationError({ ...validationError, [input.target]: false }) + // console.log('Ingen Error') + // console.log(validationError) + // } + // }) } const submit = () => { - /** - * - console.log('Metadata' + metadata) - - console.log('Field: ' + metadata?.field) - console.log('Formation: ' + metadata?.formation) - - console.log('Type Formation: ' + typeof metadata?.formation) - console.log('Type Field: ' + typeof metadata?.field) - */ - - validateInput(metadata?.field, 'field') - - validateInput(metadata?.formation, 'formation') - /** - * -console.log('Field error: ' + validationError.field) -console.log('Formation error: ' + validationError.formation) -*/ - - // confirm() + console.log(metadata) + validateInput([ + { values: metadata?.field, target: 'field' }, + { values: metadata?.formation, target: 'formation' }, + ]) + validateInput() + console.log(validationError) } return ( @@ -93,7 +89,7 @@ console.log('Formation error: ' + validationError.formation) /> {isFileDisplay && } void + // onValidate: (values: string[], target: string) => void validationError: { field: boolean; formation: boolean } metadata: Partial | undefined setMetadata: (metadata: Partial) => void @@ -29,8 +29,8 @@ export const ModelMetadata = ({ } const handleInput = (e: AutocompleteChanges, target: string) => { - onValidate(e.selectedItems, target) setMetadata({ ...metadata, [target]: e.selectedItems }) + // onValidate(e.selectedItems, target) } return (