@@ -22,6 +22,12 @@ $(function (){
2222 if ( $ ( this ) . val ( ) === "" ) {
2323 $ ( this ) . addClass ( "empty" ) ;
2424 }
25+
26+ if ( $ ( this ) . parent ( ) . next ( ) . is ( "[type=file]" ) ) {
27+ $ ( this ) . parent ( ) . addClass ( "fileinput" ) ;
28+ var $input = $ ( this ) . parent ( ) . next ( ) . detach ( ) ;
29+ $ ( this ) . after ( $input ) ;
30+ }
2531 } ) ;
2632
2733 $ ( document ) . on ( "keyup change" , ".form-control" , function ( ) {
@@ -31,8 +37,29 @@ $(function (){
3137 $ ( this ) . addClass ( "empty" ) ;
3238 }
3339 } ) ;
34- $ ( document ) . on ( "keydown" , ".form-control" , function ( ) {
40+ $ ( document ) . on ( "keydown change " , ".form-control" , function ( ) {
3541 $ ( this ) . removeClass ( "empty" ) ;
3642 } ) ;
43+ $ ( document )
44+ . on ( "focus" , ".form-control-wrapper.fileinput" , function ( ) {
45+ $ ( this ) . find ( "input" ) . addClass ( "focus" ) ;
46+ } )
47+ . on ( "blur" , ".form-control-wrapper.fileinput" , function ( ) {
48+ $ ( this ) . find ( "input" ) . removeClass ( "focus" ) ;
49+ } )
50+ . on ( "change" , ".form-control-wrapper.fileinput [type=file]" , function ( ) {
51+ var value = "" ;
52+ $ . each ( $ ( this ) [ 0 ] . files , function ( i , file ) {
53+ console . log ( file ) ;
54+ value += file . name + ", " ;
55+ } ) ;
56+ value = value . substring ( 0 , value . length - 2 ) ;
57+ if ( value ) {
58+ $ ( this ) . prev ( ) . removeClass ( "empty" ) ;
59+ } else {
60+ $ ( this ) . prev ( ) . addClass ( "empty" ) ;
61+ }
62+ $ ( this ) . prev ( ) . val ( value ) ;
63+ } ) ;
3764} ) ;
3865
0 commit comments