@@ -6,8 +6,16 @@ import { FileUploadFieldComponent } from "@xgovformbuilder/model";
6
6
import { FormModel } from "server/plugins/engine/models" ;
7
7
import joi , { Schema } from "joi" ;
8
8
9
+ type FileUploadAttributes = {
10
+ accept : string ;
11
+ multiple ?: string ;
12
+ } ;
13
+
9
14
export class FileUploadField extends FormComponent {
10
15
dataType = "file" as DataType ;
16
+ attributes : FileUploadAttributes = {
17
+ accept : "image/jpeg,image/gif,image/png,application/pdf" ,
18
+ } ;
11
19
12
20
constructor ( def : FileUploadFieldComponent , model : FormModel ) {
13
21
super ( def , model ) ;
@@ -20,6 +28,14 @@ export class FileUploadField extends FormComponent {
20
28
componentSchema = componentSchema . allow ( "" ) . allow ( null ) ;
21
29
}
22
30
31
+ if ( options . multiple ) {
32
+ this . attributes . multiple = "multiple" ;
33
+ }
34
+
35
+ if ( options . accept ) {
36
+ this . attributes . accept = options . accept ;
37
+ }
38
+
23
39
componentSchema = componentSchema . messages ( {
24
40
"string.empty" : "Upload {{#label}}" ,
25
41
} ) ;
@@ -40,12 +56,6 @@ export class FileUploadField extends FormComponent {
40
56
return { [ this . name ] : this . schema as Schema } ;
41
57
}
42
58
43
- get attributes ( ) {
44
- return {
45
- accept : "image/jpeg,image/gif,image/png,application/pdf" ,
46
- } ;
47
- }
48
-
49
59
getViewModel ( formData : FormData , errors : FormSubmissionErrors ) {
50
60
const { options } = this ;
51
61
const viewModel : ViewModel = {
0 commit comments