11import { getBlankData } from './data' ;
2- import { Button , FormInput , CheckInput , FormRow , FormGroup } from './components' ;
2+ import { Button , FormInput , FormCheckInput , FormRadioInput , FormSelectInput ,
3+ FormRow , FormGroup } from './components' ;
34import { getVerboseName } from './util' ;
45
56
6- const TYPE_MAP = {
7- string : 'text' ,
8- boolean : 'checkbox' ,
9- number : 'number'
10- } ;
11-
12- const FIELD_MAP = {
13- string : FormInput ,
14- integer : FormInput ,
15- number : FormInput ,
16- boolean : CheckInput
17- } ;
18-
19-
20- function handleChange ( e , type , callback ) {
7+ function handleChange ( e , valueType , callback ) {
8+ let type = e . target . type
219 let value ;
22- if ( type === 'text' ) {
10+
11+ if ( type === 'checkbox' ) {
12+ value = e . target . checked ;
13+ } else {
2314 value = e . target . value ;
2415 }
25- else if ( type === 'number' ) {
26- value = e . target . value . trim ( ) ;
2716
17+ if ( valueType === 'number' ) {
18+ value = value . trim ( ) ;
2819 if ( value !== '' && ! isNaN ( Number ( value ) ) )
2920 value = Number ( value ) ;
3021 }
31- else if ( type === 'checkbox' ) {
32- value = e . target . checked ;
33- }
3422
3523 callback ( e . target . name , value ) ;
3624}
@@ -45,18 +33,13 @@ function FormField(props) {
4533 let type = props . schema . type ;
4634 if ( props . schema . choices ) {
4735 inputProps . options = props . schema . choices ;
48- if ( props . schema . multi )
49- type = 'multiselect' ;
50- else
51- type = 'select' ;
36+ type = 'select' ;
5237 }
5338 if ( props . schema . widget )
5439 type = props . schema . widget ;
5540
5641 let InputField ;
5742
58- console . log ( type )
59-
6043 switch ( type ) {
6144 case 'string' :
6245 inputProps . type = 'text' ;
@@ -72,23 +55,18 @@ function FormField(props) {
7255 break ;
7356 case 'boolean' :
7457 inputProps . type = 'checkbox' ;
75- InputField = CheckInput ;
58+ InputField = FormCheckInput ;
7659 break ;
7760 case 'checkbox' :
7861 inputProps . type = 'checkbox' ;
79- InputField = CheckInput ;
62+ InputField = FormCheckInput ;
8063 break ;
8164 case 'radio' :
82- inputProps . type = 'checkbox ' ;
83- InputField = CheckInput ;
65+ inputProps . type = 'radio ' ;
66+ InputField = FormRadioInput ;
8467 break ;
8568 case 'select' :
86- inputProps . type = 'checkbox' ;
87- InputField = CheckInput ;
88- break ;
89- case 'multiselect' :
90- inputProps . type = 'checkbox' ;
91- InputField = CheckInput ;
69+ InputField = FormSelectInput ;
9270 break ;
9371 default :
9472 inputProps . type = 'text' ;
@@ -103,7 +81,7 @@ function FormField(props) {
10381 :
10482 props . schema . title
10583 }
106- onChange = { ( e ) => handleChange ( e , inputProps . type , props . onChange ) }
84+ onChange = { ( e ) => handleChange ( e , props . schema . type , props . onChange ) }
10785 />
10886 ) ;
10987}
0 commit comments