-
Notifications
You must be signed in to change notification settings - Fork 3
Validate forms on submit, restyle validation messages #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,9 @@ export const AddTestToIdentifierPage: FC = () => { | |
| }); | ||
|
|
||
| const fieldError = (key: keyof FormFields) => | ||
| form.touched[key] && form.errors[key] ? <Text>{form.errors[key]}</Text> : null; | ||
| (form.submitCount > 0 || form.touched[key]) && form.errors[key] ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seen this logic three times now, maybe you should move to a library?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, will see if I can create a type-safe component 👍 |
||
| <Text variant="validation">{form.errors[key]}</Text> | ||
| ) : null; | ||
|
|
||
| return ( | ||
| <> | ||
|
|
@@ -128,7 +130,7 @@ export const AddTestToIdentifierPage: FC = () => { | |
|
|
||
| {selectedTestType && <TestFields form={form} testType={selectedTestType} />} | ||
|
|
||
| <Button variant="block" type="submit" disabled={!form.isValid || creating}> | ||
| <Button variant="block" type="submit" disabled={creating}> | ||
| <Message>addTestToIdentifierPage.button</Message> | ||
| </Button> | ||
| </AnyBox> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,11 @@ interface TestFieldsProps { | |
|
|
||
| export const TestFields: FC<TestFieldsProps> = ({ form, testType }) => { | ||
| const fieldError = (key: keyof TestType['resultsSchema']['properties']) => | ||
| form.touched[key] && form.errors[key] ? <Text>{form.errors[key]}</Text> : null; | ||
| (form.submitCount > 0 || form.touched[key]) && form.errors[key] ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 :-) |
||
| <Text variant="validation"> | ||
| <Message>testFields.error.generic</Message> | ||
| </Text> | ||
| ) : null; | ||
|
|
||
| // TODO: Extract generic JSON schema generator | ||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly odd phrase. Perhaps something more like "Invalid value, please try again"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, tried to follow the Please x phrasing of the other messages, but it ended up weird.