Skip to content
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

chore (indicator types list): add extra form validation #450

Merged
merged 15 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-11-27T08:30:38.416Z\n"
"PO-Revision-Date: 2024-11-27T08:30:38.417Z\n"
"POT-Creation-Date: 2024-11-26T14:06:00.934Z\n"
"PO-Revision-Date: 2024-11-26T14:06:00.934Z\n"

Expand Down
2 changes: 1 addition & 1 deletion src/components/form/fields/DateField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from '@dhis2/d2-i18n'
import { CalendarInput, CalendarInputProps } from '@dhis2/ui'
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import { useField } from 'react-final-form'
import { selectedLocale, useSystemSetting } from '../../../lib'

Expand Down Expand Up @@ -31,7 +31,7 @@
error: false,
})

const { input, meta } = useField<string | undefined>(name)

Check warning on line 34 in src/components/form/fields/DateField.tsx

View workflow job for this annotation

GitHub Actions / lint

'meta' is assigned a value but never used

const handleChange: CalendarInputProps['onDateSelect'] = (
payload: {
Expand Down
11 changes: 10 additions & 1 deletion src/pages/indicatorTypes/form/IndicatorTypesSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import { getDefaults, createFormValidate, modelFormSchemas } from '../../../lib'
const { identifiable } = modelFormSchemas

export const IndicatorSchema = identifiable.extend({
factor: z.coerce.number().int(),
factor: z.coerce
.number({ invalid_type_error: 'Please enter a number' })
.int()
.max(
Number.MAX_SAFE_INTEGER,
`The number is too large. Please enter a valid integer.`
)
.refine((value) => value !== 0, {
message: 'Zero is not a valid value for factor',
}),
})

export const initialValues = getDefaults(IndicatorSchema)
Expand Down
Loading