@@ -37,6 +37,7 @@ type Msg
3737 | SelectChanged ( Field . Msg () )
3838 | RadioChanged ( Field . Msg () )
3939 | CheckboxChanged ( Field . Msg () )
40+ | FileChanged ( Field . Msg () )
4041 | GroupChanged ( Field . Msg ContactFields )
4142 | RepeatableChanged ( Field . Msg ContactFields )
4243 | Repeatable2Changed ( Field . Msg ContactFields )
@@ -59,6 +60,7 @@ type alias Model =
5960 , select : Field ()
6061 , radio : Field ()
6162 , checkbox : Field ()
63+ , file : Field ()
6264 , group : Field ContactFields
6365 , repeatable : Field ContactFields
6466 , repeatableWithDefaults : Field ContactFields
8385 , select = selectField
8486 , radio = radioField
8587 , checkbox = checkboxField
88+ , file = fileField
8689 , group = groupField
8790 , repeatable = repeatableField
8891 , repeatableWithDefaults = repeatableFieldWithDefaults
@@ -257,6 +260,16 @@ update msg book =
257260 ( Task . succeed ( Debug . toString result))
258261 )
259262
263+ FileChanged fieldMsg ->
264+ let
265+ ( updatedField, result ) =
266+ Parse . parseUpdate Parse . file fieldMsg model. file
267+ in
268+ ( { model | file = updatedField }
269+ , Task . perform ( Actions . logActionWithString " Result" )
270+ ( Task . succeed ( Debug . toString result))
271+ )
272+
260273 GroupChanged fieldMsg ->
261274 let
262275 ( updatedField, result ) =
@@ -423,6 +436,14 @@ chapter =
423436 ]
424437 |> Html . map ( Actions . updateStateWithCmdWith update)
425438 )
439+ , ( " File"
440+ , \ book ->
441+ Html . div [ Attr . class " milligram" ]
442+ [ book. fields. file
443+ |> Field . toHtml FileChanged
444+ ]
445+ |> Html . map ( Actions . updateStateWithCmdWith update)
446+ )
426447 , ( " Group"
427448 , \ book ->
428449 Html . div [ Attr . class " milligram" ]
@@ -808,6 +829,29 @@ checkboxField =
808829Parsed using `Parse.bool`.
809830
810831
832+ ### File
833+
834+ A file upload input field with drag and drop support. Files can be dropped onto
835+ the input area or selected via the native file picker. The `min` and `max`
836+ attributes can be used to validate file size in bytes.
837+
838+ ```elm
839+ fileField : Field ()
840+ fileField =
841+ Field.file
842+ [ Field.label "File Upload"
843+ , Field.placeholder "Choose a file or drag and drop"
844+ , Field.hint "Maximum file size: 5MB"
845+ , Field.max (Value.int 5242880)
846+ , Field.required True
847+ ]
848+ ```
849+
850+ <component with-label="File"/>
851+
852+ Parsed using `Parse.file`.
853+
854+
811855## Groupping Fields
812856
813857
@@ -1133,6 +1177,17 @@ checkboxField =
11331177 ]
11341178
11351179
1180+ fileField : Field ()
1181+ fileField =
1182+ Field . file
1183+ [ Field . label " File Upload"
1184+ , Field . placeholder " Choose a file or drag and drop"
1185+ , Field . hint " Maximum file size: 5MB"
1186+ , Field . max ( Value . int 5242880 )
1187+ , Field . required True
1188+ ]
1189+
1190+
11361191groupField : Field ContactFields
11371192groupField =
11381193 Field . group
0 commit comments