This repository was archived by the owner on Mar 4, 2025. It is now read-only.
File tree 3 files changed +74
-0
lines changed
app/directives/file-form-field
3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular . module ( 'tcUIComponents' ) . directive ( 'fileFormField' , fileFormField ) ;
5
+
6
+ function fileFormField ( ) {
7
+ return {
8
+ restrict : 'E' ,
9
+ templateUrl : 'directives/file-form-field/file-form-field.html' ,
10
+ scope : {
11
+ labelText : '@' ,
12
+ fieldId : '@' ,
13
+ placeholder : '@' ,
14
+ fileType : '@' ,
15
+ mandatory : '=' ,
16
+ buttonText : '@' ,
17
+ setFileReference : '&'
18
+ } ,
19
+ link : function ( scope , element , attrs ) {
20
+ scope . selectFile = selectFile ;
21
+
22
+ // fieldId is not set on element at this point, so grabbing with class .none
23
+ // which exists on the element right away
24
+ var fileInput = $ ( element [ 0 ] ) . find ( '.none' ) ;
25
+ var fileNameInput = $ ( element [ 0 ] ) . find ( 'input[type=text]' ) ;
26
+
27
+ fileInput . bind ( 'change' , function ( ) {
28
+ var file = fileInput [ 0 ] . files [ 0 ] ;
29
+
30
+ // Pass file object up through callback into controller
31
+ scope . setFileReference ( { file : file , fieldId : scope . fieldId } ) ;
32
+
33
+ // Set the file name as the value of the disabled input
34
+ fileNameInput [ 0 ] . value = file . name ;
35
+ } ) ;
36
+
37
+ function selectFile ( ) {
38
+ fileInput . click ( ) ;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ .labelwrapper
2
+ label.tc-label {{labelText}}
3
+ span.lowercase ( ng-if ="fileType" ) {{fileType | addBeginningSpace}}
4
+
5
+ span.tc-label__mandatory ( ng-if ="mandatory" ) #[ span *] mandatory
6
+
7
+ .changenamelater
8
+ input( type ="text" , placeholder ="{{placeholder}}" , disabled )
9
+
10
+ button.tc-btn ( ng-click ="selectFile()" ) {{buttonText}}
11
+
12
+ input.none ( type ="file" , id ="{{fieldId}}" )
Original file line number Diff line number Diff line change
1
+ /* jshint -W117, -W030 */
2
+ describe ( 'File Form Field Directive' , function ( ) {
3
+ var scope ;
4
+
5
+ // USE AS TEMPLATE FOR DIRECTIVES
6
+
7
+ beforeEach ( function ( ) {
8
+ bard . appModule ( 'tcUIComponents' ) ;
9
+ bard . inject ( this , '$compile' , '$rootScope' ) ;
10
+ } ) ;
11
+
12
+ bard . verifyNoOutstandingHttpRequests ( ) ;
13
+
14
+ xdescribe ( '' , function ( ) {
15
+ beforeEach ( function ( ) { } ) ;
16
+
17
+ it ( '' , function ( ) { } ) ;
18
+ } ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments