@@ -3,9 +3,25 @@ import { Button, Card, Form, Icon } from 'antd';
33import { get } from 'lodash' ;
44import React from 'react' ;
55
6- const { uuid } = window as any ;
6+ const randomByte = ( ) => {
7+ const seq = Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER ) . toString ( 16 ) ;
8+ return seq . substr ( seq . length - 1 , 1 ) ;
9+ } ;
10+ const randomBytes = length =>
11+ Array . from ( { length } )
12+ . map ( randomByte )
13+ . join ( '' ) ;
14+ const randomUuid = ( ) => [ 8 , 4 , 4 , 4 , 12 ] . map ( randomBytes ) . join ( '-' ) ;
15+
16+ const { uuid = { v4 : randomUuid } } = window as any ;
17+
18+ const initialToken = uuid . v4 ( ) ;
19+
20+ const getItems = ( { initialValue, field } : PrimeFieldProps ) => {
21+ if ( ! field . options . repeated ) {
22+ return [ [ initialToken , 0 ] ] ;
23+ }
724
8- const getItems = ( { initialValue } : PrimeFieldProps ) => {
925 if ( Array . isArray ( initialValue ) ) {
1026 return initialValue . map ( ( _ , index ) => [ uuid . v4 ( ) , index ] ) ;
1127 }
@@ -105,6 +121,10 @@ export class InputComponent extends React.PureComponent<PrimeFieldProps, any> {
105121 const { field } = this . props ;
106122 const repeated = get ( field , 'options.repeated' , false ) ;
107123
124+ if ( field . fields . length === 0 ) {
125+ return null ;
126+ }
127+
108128 return (
109129 < Form . Item label = { field . title } className = "prime-group" >
110130 { items . map ( this . renderGroupItem ) }
0 commit comments