Skip to content

Commit 8ccd757

Browse files
committed
TCA-451 - validate url fields on backend project
1 parent d22a7f2 commit 8ccd757

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

client/src/components/formHelpers/form-fields.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ function FormFields(props: FormFieldsProps): JSX.Element {
8686
return (
8787
<FormGroup key={key} className='embedded'>
8888
{type === 'hidden' ? null : (
89-
<ControlLabel htmlFor={key}>{label}</ControlLabel>
89+
<ControlLabel htmlFor={key}>
90+
{label}
91+
{required.includes(name) && (
92+
<span className='required-star'>*</span>
93+
)}
94+
</ControlLabel>
9095
)}
9196
<FormControl
9297
componentClass={type === 'textarea' ? type : 'input'}

client/src/components/formHelpers/form.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FORM_ERROR } from 'final-form';
12
import React, { FormEvent } from 'react';
23
import { Form } from 'react-final-form';
34

@@ -45,8 +46,16 @@ function DynamicForm({
4546
onSubmit={(values: URLValues, ...args: unknown[]) => {
4647
submit(formatUrlValues(values, options), ...args);
4748
}}
49+
validate={(values: URLValues) => {
50+
const hasMissingRequiredFields = options.required?.some((field: string) => !values[field]);
51+
52+
return {
53+
[FORM_ERROR]: hasMissingRequiredFields,
54+
}
55+
}}
4856
>
4957
{({ handleSubmit, pristine, error }) => (
58+
console.log(error),
5059
<form
5160
id={`dynamic-${id}`}
5261
onSubmit={handleSubmit as (e: FormEvent) => void}

client/src/components/layouts/global.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ fieldset[disabled] .btn-primary.focus {
500500
strong {
501501
color: var(--secondary-color);
502502
}
503+
.required-star {
504+
color: red;
505+
margin-left: 3px;
506+
}
503507

504508
.form-group.embedded {
505509
border: 1px solid var(--tc-black-40);

0 commit comments

Comments
 (0)