@@ -164,7 +164,7 @@ var SelectElement = React.createClass({
164
164
name : '' ,
165
165
options : { } ,
166
166
label : '' ,
167
- value : null ,
167
+ value : undefined ,
168
168
id : '' ,
169
169
class : '' ,
170
170
multiple : false ,
@@ -178,32 +178,10 @@ var SelectElement = React.createClass({
178
178
}
179
179
} ;
180
180
} ,
181
- componentDidMount : function componentDidMount ( ) {
182
- if ( this . props . value ) {
183
- this . setState ( {
184
- value : this . props . value
185
- } ) ;
186
- }
187
- } ,
188
- componentWillReceiveProps : function componentWillReceiveProps ( ) {
189
- if ( this . props . hasError ) {
190
- this . setState ( {
191
- hasError : this . props . hasError
192
- } ) ;
193
- }
194
- } ,
195
- getInitialState : function getInitialState ( ) {
196
- var value = this . props . multiple ? [ ] : '' ;
197
- return {
198
- value : value ,
199
- hasError : false
200
- } ;
201
- } ,
181
+
202
182
handleChange : function handleChange ( e ) {
203
183
var value = e . target . value ;
204
184
var options = e . target . options ;
205
- var hasError = false ;
206
- var isEmpty = value === "" ;
207
185
208
186
// Multiple values
209
187
if ( this . props . multiple && options . length > 1 ) {
@@ -213,19 +191,8 @@ var SelectElement = React.createClass({
213
191
value . push ( options [ i ] . value ) ;
214
192
}
215
193
}
216
- isEmpty = value . length > 1 ;
217
194
}
218
195
219
- // Check for errors
220
- if ( this . props . required && isEmpty ) {
221
- hasError = true ;
222
- }
223
-
224
- this . setState ( {
225
- value : value ,
226
- hasError : hasError
227
- } ) ;
228
-
229
196
this . props . onUserInput ( this . props . name , value ) ;
230
197
} ,
231
198
render : function render ( ) {
@@ -253,7 +220,7 @@ var SelectElement = React.createClass({
253
220
}
254
221
255
222
// Add error message
256
- if ( this . state . hasError ) {
223
+ if ( this . props . hasError || this . props . required && this . props . value === "" ) {
257
224
errorMessage = React . createElement (
258
225
'span' ,
259
226
null ,
@@ -281,7 +248,7 @@ var SelectElement = React.createClass({
281
248
multiple : multiple ,
282
249
className : 'form-control' ,
283
250
id : this . props . label ,
284
- value : this . state . value ,
251
+ value : this . props . value ,
285
252
onChange : this . handleChange ,
286
253
required : required ,
287
254
disabled : disabled
@@ -332,20 +299,7 @@ var TextareaElement = React.createClass({
332
299
}
333
300
} ;
334
301
} ,
335
- getInitialState : function getInitialState ( ) {
336
- return {
337
- value : ''
338
- } ;
339
- } ,
340
- componentDidMount : function componentDidMount ( ) {
341
- if ( this . props . value ) {
342
- this . setState ( { value : this . props . value } ) ;
343
- }
344
- } ,
345
302
handleChange : function handleChange ( e ) {
346
- this . setState ( {
347
- value : e . target . value
348
- } ) ;
349
303
this . props . onUserInput ( this . props . name , e . target . value ) ;
350
304
} ,
351
305
render : function render ( ) {
@@ -380,7 +334,7 @@ var TextareaElement = React.createClass({
380
334
className : 'form-control' ,
381
335
name : this . props . name ,
382
336
id : this . props . id ,
383
- value : this . state . value ,
337
+ value : this . props . value ,
384
338
required : required ,
385
339
disabled : disabled ,
386
340
onChange : this . handleChange
@@ -406,11 +360,6 @@ var TextboxElement = React.createClass({
406
360
required : React . PropTypes . bool ,
407
361
onUserInput : React . PropTypes . func
408
362
} ,
409
- getInitialState : function getInitialState ( ) {
410
- return {
411
- value : ''
412
- } ;
413
- } ,
414
363
getDefaultProps : function getDefaultProps ( ) {
415
364
return {
416
365
name : '' ,
@@ -424,17 +373,7 @@ var TextboxElement = React.createClass({
424
373
}
425
374
} ;
426
375
} ,
427
- componentDidMount : function componentDidMount ( ) {
428
- if ( this . props . value ) {
429
- this . setState ( {
430
- value : this . props . value
431
- } ) ;
432
- }
433
- } ,
434
376
handleChange : function handleChange ( e ) {
435
- this . setState ( {
436
- value : e . target . value
437
- } ) ;
438
377
this . props . onUserInput ( this . props . name , e . target . value ) ;
439
378
} ,
440
379
render : function render ( ) {
@@ -468,7 +407,7 @@ var TextboxElement = React.createClass({
468
407
className : 'form-control' ,
469
408
name : this . props . name ,
470
409
id : this . props . id ,
471
- value : this . state . value ,
410
+ value : this . props . value ,
472
411
required : required ,
473
412
disabled : disabled ,
474
413
onChange : this . handleChange
@@ -509,20 +448,7 @@ var DateElement = React.createClass({
509
448
}
510
449
} ;
511
450
} ,
512
- getInitialState : function getInitialState ( ) {
513
- return {
514
- value : ''
515
- } ;
516
- } ,
517
- componentDidMount : function componentDidMount ( ) {
518
- if ( this . props . value ) {
519
- this . setState ( { value : this . props . value } ) ;
520
- }
521
- } ,
522
451
handleChange : function handleChange ( e ) {
523
- this . setState ( {
524
- value : e . target . value
525
- } ) ;
526
452
this . props . onUserInput ( this . props . name , e . target . value ) ;
527
453
} ,
528
454
render : function render ( ) {
@@ -559,7 +485,7 @@ var DateElement = React.createClass({
559
485
min : this . props . minYear ,
560
486
max : this . props . maxYear ,
561
487
onChange : this . handleChange ,
562
- value : this . state . value ,
488
+ value : this . props . value ,
563
489
required : required ,
564
490
disabled : disabled
565
491
} )
@@ -586,11 +512,6 @@ var NumericElement = React.createClass({
586
512
required : React . PropTypes . bool ,
587
513
onUserInput : React . PropTypes . func
588
514
} ,
589
- getInitialState : function getInitialState ( ) {
590
- return {
591
- value : ''
592
- } ;
593
- } ,
594
515
getDefaultProps : function getDefaultProps ( ) {
595
516
return {
596
517
name : '' ,
@@ -606,17 +527,7 @@ var NumericElement = React.createClass({
606
527
}
607
528
} ;
608
529
} ,
609
- componentDidMount : function componentDidMount ( ) {
610
- if ( this . props . value ) {
611
- this . setState ( {
612
- value : this . props . value
613
- } ) ;
614
- }
615
- } ,
616
530
handleChange : function handleChange ( e ) {
617
- this . setState ( {
618
- value : e . target . value
619
- } ) ;
620
531
this . props . onUserInput ( this . props . name , e . target . value ) ;
621
532
} ,
622
533
render : function render ( ) {
@@ -970,9 +881,6 @@ var ButtonElement = React.createClass({
970
881
type : React . PropTypes . string ,
971
882
onUserInput : React . PropTypes . func
972
883
} ,
973
- getInitialState : function getInitialState ( ) {
974
- return { } ;
975
- } ,
976
884
getDefaultProps : function getDefaultProps ( ) {
977
885
return {
978
886
label : 'Submit' ,
0 commit comments