revert to access form.prefixName instead of context

fixes https://github.com/ohmyform/ohmyform/issues/150
This commit is contained in:
Michael Schramm 2022-02-26 22:10:39 +01:00
parent bc56a70fea
commit 1e2eb5792f

View File

@ -1,5 +1,4 @@
import { Form, InputNumber, Slider } from 'antd' import { Form, InputNumber, Slider } from 'antd'
import FormItemContext from 'rc-field-form/lib/FieldContext'
import React from 'react' import React from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { AdminFieldTypeProps } from './type.props' import { AdminFieldTypeProps } from './type.props'
@ -11,11 +10,12 @@ export const SliderType: React.FC<AdminFieldTypeProps> = (props) => {
<div> <div>
<Form.Item shouldUpdate noStyle> <Form.Item shouldUpdate noStyle>
{(form) => { {(form) => {
const context = React.useContext(FormItemContext) //const prefix = React.useContext(FormItemContext).prefixName
const prefix = (form as any).prefixName
const getValue = (name, defaultValue: number): number => { const getValue = (name, defaultValue: number): number => {
const current: unknown = form.getFieldValue([ const current: unknown = form.getFieldValue([
...context.prefixName, ...prefix,
props.field.name as string, props.field.name as string,
'optionKeys', 'optionKeys',
name, name,
@ -51,7 +51,9 @@ export const SliderType: React.FC<AdminFieldTypeProps> = (props) => {
<Form.Item <Form.Item
label={t('type:slider.min')} label={t('type:slider.min')}
name={[ name={[
props.field.name as string, 'optionKeys', 'min', props.field.name as string,
'optionKeys',
'min',
]} ]}
labelCol={{ span: 6 }} labelCol={{ span: 6 }}
initialValue={0} initialValue={0}
@ -66,7 +68,9 @@ props.field.name as string, 'optionKeys', 'min',
<Form.Item <Form.Item
label={t('type:slider.max')} label={t('type:slider.max')}
name={[ name={[
props.field.name as string, 'optionKeys', 'max', props.field.name as string,
'optionKeys',
'max',
]} ]}
labelCol={{ span: 6 }} labelCol={{ span: 6 }}
initialValue={100} initialValue={100}
@ -81,7 +85,9 @@ props.field.name as string, 'optionKeys', 'max',
<Form.Item <Form.Item
label={t('type:slider.step')} label={t('type:slider.step')}
name={[ name={[
props.field.name as string, 'optionKeys', 'step', props.field.name as string,
'optionKeys',
'step',
]} ]}
labelCol={{ span: 6 }} labelCol={{ span: 6 }}
initialValue={1} initialValue={1}