Skip to content

Commit b98dcb1

Browse files
authored
Merge pull request #75 from topcoder-platform/TCA-451_update-form-layout-for-backend-project
Tca 451 update form layout for backend project
2 parents 53d7124 + c6885c5 commit b98dcb1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-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: 12 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,6 +46,17 @@ 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(
51+
(field: string) => !values[field]
52+
);
53+
54+
return hasMissingRequiredFields
55+
? {
56+
[FORM_ERROR]: hasMissingRequiredFields
57+
}
58+
: undefined;
59+
}}
4860
>
4961
{({ handleSubmit, pristine, error }) => (
5062
<form

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)