Skip to content

Commit

Permalink
fix: format factor from number to string on edit (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic authored Dec 11, 2024
1 parent 69cac06 commit 338d4c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
28 changes: 28 additions & 0 deletions src/pages/indicatorTypes/form/FactorField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import React from 'react'
import { useField } from 'react-final-form'
import { useSchemaSectionHandleOrThrow } from '../../../lib'
import { useValidator } from '../../../lib/models/useFieldValidators'

export const FactorField = () => {
const fieldName = 'factor'
const schemaSection = useSchemaSectionHandleOrThrow()
const validate = useValidator({ schemaSection, property: 'factor' })

const { input, meta } = useField(fieldName, {
validate,
type: 'number',
format: (value) => value?.toString(),
})

return (
<InputFieldFF
input={input}
meta={meta}
inputWidth="400px"
label={i18n.t('Factor')}
required
/>
)
}
16 changes: 2 additions & 14 deletions src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import {
CustomAttributesSection,
StandardFormField,
Expand All @@ -11,14 +9,12 @@ import {
NameField,
} from '../../../components'
import { SECTIONS_MAP, useSchemaSectionHandleOrThrow } from '../../../lib'
import { useValidator } from '../../../lib/models/useFieldValidators'
import { FactorField } from './FactorField'

export const IndicatorTypesFormFields = () => {
const section = SECTIONS_MAP.indicatorType
const schemaSection = useSchemaSectionHandleOrThrow()

const validateFactor = useValidator({ schemaSection, property: 'factor' })

return (
<>
<StandardFormSection>
Expand All @@ -36,15 +32,7 @@ export const IndicatorTypesFormFields = () => {
</StandardFormField>

<StandardFormField>
<Field
name="factor"
type="number"
inputWidth="400px"
component={InputFieldFF}
label={i18n.t('Factor')}
validate={validateFactor}
required
/>
<FactorField />
</StandardFormField>
</StandardFormSection>

Expand Down

0 comments on commit 338d4c7

Please sign in to comment.