mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Extract specific field definition
This commit is contained in:
		| @@ -39,12 +39,25 @@ function ApiFormField({ | |||||||
|   field: ApiFormFieldType; |   field: ApiFormFieldType; | ||||||
|   definitions: ApiFormFieldType[]; |   definitions: ApiFormFieldType[]; | ||||||
| }) { | }) { | ||||||
|   useEffect(() => { |   // Extract field definition from provided data | ||||||
|     console.log('field:', field); |   // Where user has provided specific data, override the API definition | ||||||
|     console.log('definitions:', definitions); |   const definition: ApiFormFieldType = useMemo(() => { | ||||||
|   }, []); |     let def = definitions.find((def) => def.name == field.name) || field; | ||||||
|  |  | ||||||
|   return <Text>{field.name}</Text>; |     return { | ||||||
|  |       ...def, | ||||||
|  |       ...field | ||||||
|  |     }; | ||||||
|  |   }, [field, definitions]); | ||||||
|  |  | ||||||
|  |   switch (definition.type) { | ||||||
|  |     default: | ||||||
|  |       return ( | ||||||
|  |         <Alert color="red" title="Error"> | ||||||
|  |           Unknown field type for field '{definition.name}': {definition.type} | ||||||
|  |         </Alert> | ||||||
|  |       ); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user