фикс багов
This commit is contained in:
@@ -74,10 +74,36 @@ const FormElement: FC<FormElementProps> = ({ element, value, onChange }) => {
|
||||
const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
||||
const [formData, setFormData] = useState<Record<string, any>>({})
|
||||
const [showSpreadsheet, setShowSpreadsheet] = useState(false)
|
||||
const [isInitialized, setIsInitialized] = useState(false)
|
||||
const engineRef = useRef<any>(null)
|
||||
const toast = useToast()
|
||||
const navigate = useNavigate()
|
||||
|
||||
// Инициализация значений для специальных элементов
|
||||
useEffect(() => {
|
||||
if (!isInitialized && template.elements.length > 0) {
|
||||
const initialData: Record<string, any> = {}
|
||||
|
||||
template.elements.forEach(element => {
|
||||
// Получаем определение элемента
|
||||
const elementDefinition = getElementDefinition(element.type)
|
||||
if (elementDefinition?.getInitialValue) {
|
||||
// Используем метод getInitialValue для получения начального значения
|
||||
const initialValue = elementDefinition.getInitialValue(element as any)
|
||||
if (initialValue !== undefined) {
|
||||
initialData[element.id] = initialValue
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (Object.keys(initialData).length > 0) {
|
||||
setFormData(initialData)
|
||||
}
|
||||
|
||||
setIsInitialized(true)
|
||||
}
|
||||
}, [template.elements, isInitialized])
|
||||
|
||||
const handleFieldChange = (elementId: string, value: any) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
|
||||
Reference in New Issue
Block a user