elm-pages 3.0.0-beta.33 → 3.0.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/codegen/elm-pages-codegen.cjs +165 -134
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/dead-code-review/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm.json +1 -1
- package/generator/src/RouteBuilder.elm +2 -2
- package/generator/src/cli.js +5 -9
- package/generator/src/compatibility-key.js +2 -2
- package/generator/static-code/elm-pages.js +10 -0
- package/package.json +3 -3
- package/src/BackendTask/File.elm +43 -13
- package/src/BackendTask/Internal/Request.elm +48 -3
- package/src/FatalError.elm +4 -3
- package/src/Internal/Field.elm +19 -0
- package/src/Internal/Input.elm +81 -0
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/Internal/Msg.elm +70 -61
- package/src/Pages/Internal/Platform/Cli.elm +423 -425
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +14 -8
- package/src/Pages/Internal/Platform/StaticResponses.elm +1 -7
- package/src/Pages/Internal/Platform.elm +119 -100
- package/src/Pages/ProgramConfig.elm +12 -5
- package/src/Pages/StaticHttpRequest.elm +0 -1
- package/src/Pages/Transition.elm +9 -1
- package/src/PagesMsg.elm +0 -10
- package/src/Scaffold/Form.elm +9 -9
- package/src/Server/Request.elm +57 -61
- package/src/Form/Field.elm +0 -729
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -497
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1558
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -257
- package/src/Pages/Internal/Form.elm +0 -37
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
module BackendTask.Internal.Request exposing (request)
|
|
1
|
+
module BackendTask.Internal.Request exposing (request, request2)
|
|
2
2
|
|
|
3
3
|
import BackendTask exposing (BackendTask)
|
|
4
|
-
import BackendTask.Http exposing (Body, Expect)
|
|
4
|
+
import BackendTask.Http exposing (Body, Error(..), Expect)
|
|
5
|
+
import Json.Decode exposing (Decoder)
|
|
6
|
+
import Json.Encode as Encode
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
request :
|
|
@@ -22,7 +24,50 @@ request ({ name, body, expect } as params) =
|
|
|
22
24
|
}
|
|
23
25
|
expect
|
|
24
26
|
|> BackendTask.onError
|
|
25
|
-
(\
|
|
27
|
+
(\error ->
|
|
28
|
+
let
|
|
29
|
+
_ =
|
|
30
|
+
Debug.log "BackendTask.Internal.Request" error
|
|
31
|
+
in
|
|
26
32
|
-- TODO avoid crash here, this should be handled as an internal error
|
|
27
33
|
request params
|
|
28
34
|
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
request2 :
|
|
38
|
+
{ name : String
|
|
39
|
+
, body : Body
|
|
40
|
+
, expect : Decoder a
|
|
41
|
+
, errorDecoder : Decoder error
|
|
42
|
+
, onError : Json.Decode.Error -> error
|
|
43
|
+
}
|
|
44
|
+
-> BackendTask error a
|
|
45
|
+
request2 ({ name, body, expect, onError, errorDecoder } as params) =
|
|
46
|
+
-- elm-review: known-unoptimized-recursion
|
|
47
|
+
BackendTask.Http.request
|
|
48
|
+
{ url = "elm-pages-internal://" ++ name
|
|
49
|
+
, method = "GET"
|
|
50
|
+
, headers = []
|
|
51
|
+
, body = body
|
|
52
|
+
, timeoutInMs = Nothing
|
|
53
|
+
, retries = Nothing
|
|
54
|
+
}
|
|
55
|
+
(BackendTask.Http.expectJson Json.Decode.value)
|
|
56
|
+
|> BackendTask.onError
|
|
57
|
+
(\error ->
|
|
58
|
+
BackendTask.succeed Encode.null
|
|
59
|
+
)
|
|
60
|
+
|> BackendTask.andThen
|
|
61
|
+
(\decodeValue ->
|
|
62
|
+
case Json.Decode.decodeValue errorDecoder decodeValue of
|
|
63
|
+
Ok a ->
|
|
64
|
+
BackendTask.fail a
|
|
65
|
+
|
|
66
|
+
Err _ ->
|
|
67
|
+
case Json.Decode.decodeValue expect decodeValue of
|
|
68
|
+
Ok a ->
|
|
69
|
+
BackendTask.succeed a
|
|
70
|
+
|
|
71
|
+
Err e ->
|
|
72
|
+
BackendTask.fail (onError e)
|
|
73
|
+
)
|
package/src/FatalError.elm
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module FatalError exposing (FatalError, fromString, recoverable)
|
|
1
|
+
module FatalError exposing (FatalError, build, fromString, recoverable)
|
|
2
2
|
|
|
3
3
|
{-| The Elm language doesn't have the concept of exceptions or special control flow for errors. It just has
|
|
4
4
|
Custom Types, and by convention types like `Result` and the `Err` variant are used to represent possible failure states
|
|
@@ -54,7 +54,7 @@ issue.
|
|
|
54
54
|
In the case of server-rendered Routes (`RouteBuilder.serverRender`), `elm-pages` will show your 500 error page
|
|
55
55
|
when these errors occur.
|
|
56
56
|
|
|
57
|
-
@docs FatalError, fromString, recoverable
|
|
57
|
+
@docs FatalError, build, fromString, recoverable
|
|
58
58
|
|
|
59
59
|
-}
|
|
60
60
|
|
|
@@ -66,7 +66,8 @@ type alias FatalError =
|
|
|
66
66
|
Pages.Internal.FatalError.FatalError
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
{-|
|
|
69
|
+
{-| Create a FatalError with a title and body.
|
|
70
|
+
-}
|
|
70
71
|
build : { title : String, body : String } -> FatalError
|
|
71
72
|
build info =
|
|
72
73
|
Pages.Internal.FatalError.FatalError info
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Internal.Field exposing (Field(..), FieldInfo)
|
|
2
|
+
|
|
3
|
+
{-| -}
|
|
4
|
+
|
|
5
|
+
import Json.Encode as Encode
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type Field error parsed input initial kind constraints
|
|
9
|
+
= Field (FieldInfo error parsed input initial) kind
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
{-| -}
|
|
13
|
+
type alias FieldInfo error parsed input initial =
|
|
14
|
+
{ initialValue : input -> Maybe String
|
|
15
|
+
, decode : Maybe String -> ( Maybe parsed, List error )
|
|
16
|
+
, properties : List ( String, Encode.Value )
|
|
17
|
+
, initialToString : initial -> String
|
|
18
|
+
, compare : String -> initial -> Order
|
|
19
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Internal.Input exposing
|
|
2
|
+
( Hidden(..)
|
|
3
|
+
, Input(..)
|
|
4
|
+
, InputType(..)
|
|
5
|
+
, Options(..)
|
|
6
|
+
, inputTypeToString
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
type InputType
|
|
11
|
+
= Text
|
|
12
|
+
| Number
|
|
13
|
+
-- TODO should range have arguments for initial, min, and max?
|
|
14
|
+
| Range
|
|
15
|
+
| Radio
|
|
16
|
+
-- TODO should submit be a special type, or an Input type?
|
|
17
|
+
-- TODO have an option for a submit with a name/value?
|
|
18
|
+
| Date
|
|
19
|
+
| Time
|
|
20
|
+
| Checkbox
|
|
21
|
+
| Tel
|
|
22
|
+
| Search
|
|
23
|
+
| Password
|
|
24
|
+
| Email
|
|
25
|
+
| Url
|
|
26
|
+
| Textarea { rows : Maybe Int, cols : Maybe Int }
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
inputTypeToString : InputType -> String
|
|
30
|
+
inputTypeToString inputType =
|
|
31
|
+
case inputType of
|
|
32
|
+
Text ->
|
|
33
|
+
"text"
|
|
34
|
+
|
|
35
|
+
Textarea _ ->
|
|
36
|
+
"text"
|
|
37
|
+
|
|
38
|
+
Number ->
|
|
39
|
+
"number"
|
|
40
|
+
|
|
41
|
+
Range ->
|
|
42
|
+
"range"
|
|
43
|
+
|
|
44
|
+
Radio ->
|
|
45
|
+
"radio"
|
|
46
|
+
|
|
47
|
+
Date ->
|
|
48
|
+
"date"
|
|
49
|
+
|
|
50
|
+
Time ->
|
|
51
|
+
"time"
|
|
52
|
+
|
|
53
|
+
Checkbox ->
|
|
54
|
+
"checkbox"
|
|
55
|
+
|
|
56
|
+
Tel ->
|
|
57
|
+
"tel"
|
|
58
|
+
|
|
59
|
+
Search ->
|
|
60
|
+
"search"
|
|
61
|
+
|
|
62
|
+
Password ->
|
|
63
|
+
"password"
|
|
64
|
+
|
|
65
|
+
Email ->
|
|
66
|
+
"email"
|
|
67
|
+
|
|
68
|
+
Url ->
|
|
69
|
+
"url"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
type Input
|
|
73
|
+
= Input InputType
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
type Hidden
|
|
77
|
+
= Hidden
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
type Options a
|
|
81
|
+
= Options (String -> Maybe a) (List String)
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
module Pages.Form exposing
|
|
2
|
+
( Strategy(..), renderHtml, renderStyledHtml
|
|
3
|
+
, FormWithServerValidations, Handler
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
{-|
|
|
7
|
+
|
|
8
|
+
@docs Strategy, renderHtml, renderStyledHtml
|
|
9
|
+
|
|
10
|
+
@docs FormWithServerValidations, Handler
|
|
11
|
+
|
|
12
|
+
-}
|
|
13
|
+
|
|
14
|
+
import BackendTask exposing (BackendTask)
|
|
15
|
+
import Dict exposing (Dict)
|
|
16
|
+
import FatalError exposing (FatalError)
|
|
17
|
+
import Form
|
|
18
|
+
import Form.Handler
|
|
19
|
+
import Form.Validation as Validation exposing (Validation)
|
|
20
|
+
import Html
|
|
21
|
+
import Html.Styled
|
|
22
|
+
import Pages.Internal.Msg
|
|
23
|
+
import Pages.Transition
|
|
24
|
+
import PagesMsg exposing (PagesMsg)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
{-| -}
|
|
28
|
+
type alias FormWithServerValidations error combined input view =
|
|
29
|
+
Form.Form
|
|
30
|
+
error
|
|
31
|
+
{ combine :
|
|
32
|
+
Validation
|
|
33
|
+
error
|
|
34
|
+
(BackendTask FatalError (Validation error combined Never Never))
|
|
35
|
+
Never
|
|
36
|
+
Never
|
|
37
|
+
, view : Form.Context error input -> view
|
|
38
|
+
}
|
|
39
|
+
(BackendTask FatalError (Validation error combined Never Never))
|
|
40
|
+
input
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
{-| -}
|
|
44
|
+
type alias Handler error combined =
|
|
45
|
+
Form.Handler.Handler error (BackendTask FatalError (Validation.Validation error combined Never Never))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
{-| -}
|
|
49
|
+
type Strategy
|
|
50
|
+
= Parallel
|
|
51
|
+
| Serial
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
{-| -}
|
|
55
|
+
renderHtml :
|
|
56
|
+
List (Html.Attribute (PagesMsg userMsg))
|
|
57
|
+
-> Strategy
|
|
58
|
+
-> Form.Options error parsed input userMsg
|
|
59
|
+
->
|
|
60
|
+
{ --path : Path
|
|
61
|
+
--, url : Maybe PageUrl
|
|
62
|
+
--, action : Maybe action
|
|
63
|
+
app
|
|
64
|
+
| pageFormState : Form.Model
|
|
65
|
+
, transition : Maybe Pages.Transition.Transition
|
|
66
|
+
, fetchers : Dict String (Pages.Transition.FetcherState (Maybe action))
|
|
67
|
+
}
|
|
68
|
+
-> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Html (PagesMsg userMsg)) } parsed input
|
|
69
|
+
-> Html.Html (PagesMsg userMsg)
|
|
70
|
+
renderHtml attrs strategy options_ app form_ =
|
|
71
|
+
form_
|
|
72
|
+
|> Form.renderHtml
|
|
73
|
+
{ state = app.pageFormState
|
|
74
|
+
, submitting =
|
|
75
|
+
(case app.fetchers |> Dict.get options_.id of
|
|
76
|
+
Just { status } ->
|
|
77
|
+
case status of
|
|
78
|
+
Pages.Transition.FetcherComplete _ ->
|
|
79
|
+
False
|
|
80
|
+
|
|
81
|
+
Pages.Transition.FetcherSubmitting ->
|
|
82
|
+
True
|
|
83
|
+
|
|
84
|
+
Pages.Transition.FetcherReloading _ ->
|
|
85
|
+
True
|
|
86
|
+
|
|
87
|
+
Nothing ->
|
|
88
|
+
False
|
|
89
|
+
)
|
|
90
|
+
|| (case app.transition of
|
|
91
|
+
Just (Pages.Transition.Submitting formData) ->
|
|
92
|
+
formData.id == Just options_.id
|
|
93
|
+
|
|
94
|
+
Just (Pages.Transition.LoadAfterSubmit submitData _ _) ->
|
|
95
|
+
submitData.id == Just options_.id
|
|
96
|
+
|
|
97
|
+
Just (Pages.Transition.Loading _ _) ->
|
|
98
|
+
False
|
|
99
|
+
|
|
100
|
+
Nothing ->
|
|
101
|
+
False
|
|
102
|
+
)
|
|
103
|
+
, toMsg = Pages.Internal.Msg.FormMsg
|
|
104
|
+
}
|
|
105
|
+
{ id = options_.id
|
|
106
|
+
, method = options_.method
|
|
107
|
+
, input = options_.input
|
|
108
|
+
, serverResponse = options_.serverResponse
|
|
109
|
+
, action = options_.action
|
|
110
|
+
, onSubmit =
|
|
111
|
+
Just
|
|
112
|
+
(\submission ->
|
|
113
|
+
case submission.parsed of
|
|
114
|
+
Form.Valid _ ->
|
|
115
|
+
Pages.Internal.Msg.Submit
|
|
116
|
+
{ useFetcher = strategy == Parallel
|
|
117
|
+
, action = submission.action
|
|
118
|
+
, fields = submission.fields
|
|
119
|
+
, method = submission.method
|
|
120
|
+
, msg =
|
|
121
|
+
options_.onSubmit
|
|
122
|
+
|> Maybe.map
|
|
123
|
+
(\onSubmit -> onSubmit submission)
|
|
124
|
+
, id = options_.id
|
|
125
|
+
, valid = True
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Form.Invalid _ _ ->
|
|
129
|
+
Pages.Internal.Msg.Submit
|
|
130
|
+
{ useFetcher = strategy == Parallel
|
|
131
|
+
, action = submission.action
|
|
132
|
+
, method = submission.method
|
|
133
|
+
, fields = submission.fields
|
|
134
|
+
, msg = options_.onSubmit |> Maybe.map (\onSubmit -> onSubmit submission)
|
|
135
|
+
, id = options_.id
|
|
136
|
+
, valid = False
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
attrs
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
{-| -}
|
|
144
|
+
renderStyledHtml :
|
|
145
|
+
List (Html.Styled.Attribute (PagesMsg userMsg))
|
|
146
|
+
-> Strategy
|
|
147
|
+
-> Form.Options error parsed input userMsg
|
|
148
|
+
->
|
|
149
|
+
{ --path : Path
|
|
150
|
+
--, url : Maybe PageUrl
|
|
151
|
+
--, action : Maybe action
|
|
152
|
+
app
|
|
153
|
+
| pageFormState : Form.Model
|
|
154
|
+
, transition : Maybe Pages.Transition.Transition
|
|
155
|
+
, fetchers : Dict String (Pages.Transition.FetcherState (Maybe action))
|
|
156
|
+
}
|
|
157
|
+
-> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Styled.Html (PagesMsg userMsg)) } parsed input
|
|
158
|
+
-> Html.Styled.Html (PagesMsg userMsg)
|
|
159
|
+
renderStyledHtml attrs strategy options_ app form_ =
|
|
160
|
+
form_
|
|
161
|
+
|> Form.renderStyledHtml
|
|
162
|
+
{ state = app.pageFormState
|
|
163
|
+
, toMsg = Pages.Internal.Msg.FormMsg
|
|
164
|
+
, submitting =
|
|
165
|
+
(case app.fetchers |> Dict.get options_.id of
|
|
166
|
+
Just { status } ->
|
|
167
|
+
case status of
|
|
168
|
+
Pages.Transition.FetcherComplete _ ->
|
|
169
|
+
False
|
|
170
|
+
|
|
171
|
+
Pages.Transition.FetcherSubmitting ->
|
|
172
|
+
True
|
|
173
|
+
|
|
174
|
+
Pages.Transition.FetcherReloading _ ->
|
|
175
|
+
True
|
|
176
|
+
|
|
177
|
+
Nothing ->
|
|
178
|
+
False
|
|
179
|
+
)
|
|
180
|
+
|| (case app.transition of
|
|
181
|
+
Just (Pages.Transition.Submitting formData) ->
|
|
182
|
+
formData.id == Just options_.id
|
|
183
|
+
|
|
184
|
+
Just (Pages.Transition.LoadAfterSubmit submitData _ _) ->
|
|
185
|
+
submitData.id == Just options_.id
|
|
186
|
+
|
|
187
|
+
Just (Pages.Transition.Loading _ _) ->
|
|
188
|
+
False
|
|
189
|
+
|
|
190
|
+
Nothing ->
|
|
191
|
+
False
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
{ id = options_.id
|
|
195
|
+
, method = options_.method
|
|
196
|
+
, input = options_.input
|
|
197
|
+
, serverResponse = options_.serverResponse
|
|
198
|
+
, action = options_.action
|
|
199
|
+
, onSubmit =
|
|
200
|
+
Just
|
|
201
|
+
(\submission ->
|
|
202
|
+
case submission.parsed of
|
|
203
|
+
Form.Valid _ ->
|
|
204
|
+
Pages.Internal.Msg.Submit
|
|
205
|
+
{ useFetcher = strategy == Parallel
|
|
206
|
+
, action = submission.action
|
|
207
|
+
, fields = submission.fields
|
|
208
|
+
, method = submission.method
|
|
209
|
+
, msg =
|
|
210
|
+
options_.onSubmit
|
|
211
|
+
|> Maybe.map
|
|
212
|
+
(\onSubmit -> onSubmit submission)
|
|
213
|
+
, id = options_.id
|
|
214
|
+
, valid = True
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
Form.Invalid _ _ ->
|
|
218
|
+
Pages.Internal.Msg.Submit
|
|
219
|
+
{ useFetcher = strategy == Parallel
|
|
220
|
+
, action = submission.action
|
|
221
|
+
, fields = submission.fields
|
|
222
|
+
, method = submission.method
|
|
223
|
+
, msg = options_.onSubmit |> Maybe.map (\onSubmit -> onSubmit submission)
|
|
224
|
+
, id = options_.id
|
|
225
|
+
, valid = False
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
attrs
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
module Pages.Internal.Msg exposing
|
|
2
|
-
(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
,
|
|
6
|
-
|
|
2
|
+
( Msg(..)
|
|
3
|
+
--, fetcherOnSubmit
|
|
4
|
+
|
|
5
|
+
, map
|
|
6
|
+
--, onSubmit
|
|
7
|
+
--, submitIfValid
|
|
8
|
+
|
|
7
9
|
)
|
|
8
10
|
|
|
9
|
-
import Form.FormData exposing (FormData)
|
|
10
|
-
import FormDecoder
|
|
11
|
+
--import Form.FormData exposing (FormData)
|
|
12
|
+
--import FormDecoder
|
|
13
|
+
|
|
14
|
+
import Form exposing (Method)
|
|
11
15
|
import Html exposing (Attribute)
|
|
12
16
|
import Html.Attributes as Attr
|
|
13
17
|
import Json.Decode
|
|
@@ -16,54 +20,56 @@ import Json.Decode
|
|
|
16
20
|
{-| -}
|
|
17
21
|
type Msg userMsg
|
|
18
22
|
= UserMsg userMsg
|
|
19
|
-
| Submit
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
|
23
|
+
| Submit { valid : Bool, method : Method, action : String, fields : List ( String, String ), id : String, msg : Maybe userMsg, useFetcher : Bool }
|
|
24
|
+
--| SubmitIfValid String FormData Bool (Maybe userMsg)
|
|
25
|
+
--| SubmitFetcher String FormData Bool (Maybe userMsg)
|
|
26
|
+
| FormMsg (Form.Msg (Msg userMsg))
|
|
23
27
|
| NoOp
|
|
24
28
|
|
|
25
29
|
|
|
26
|
-
{-| -}
|
|
27
|
-
onSubmit : Attribute (Msg userMsg)
|
|
28
|
-
onSubmit =
|
|
29
|
-
FormDecoder.formDataOnSubmit
|
|
30
|
-
|> Attr.map Submit
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{-| -}
|
|
34
|
-
submitIfValid : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
|
|
35
|
-
submitIfValid userMsg formId isValid =
|
|
36
|
-
FormDecoder.formDataOnSubmit
|
|
37
|
-
|> Attr.map
|
|
38
|
-
(\formData ->
|
|
39
|
-
SubmitIfValid formId
|
|
40
|
-
formData
|
|
41
|
-
(isValid formData.fields)
|
|
42
|
-
(userMsg
|
|
43
|
-
|> Maybe.map
|
|
44
|
-
(\toUserMsg ->
|
|
45
|
-
toUserMsg { fields = formData.fields }
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
)
|
|
49
|
-
|
|
50
30
|
|
|
51
|
-
{-| -}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
FormDecoder.formDataOnSubmit
|
|
55
|
-
|> Attr.map
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
31
|
+
--{-| -}
|
|
32
|
+
--onSubmit : Attribute (Msg userMsg)
|
|
33
|
+
--onSubmit =
|
|
34
|
+
-- FormDecoder.formDataOnSubmit
|
|
35
|
+
-- |> Attr.map Submit
|
|
36
|
+
--
|
|
37
|
+
--
|
|
38
|
+
--{-| -}
|
|
39
|
+
--submitIfValid : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
|
|
40
|
+
--submitIfValid userMsg formId isValid =
|
|
41
|
+
-- FormDecoder.formDataOnSubmit
|
|
42
|
+
-- |> Attr.map
|
|
43
|
+
-- (\formData ->
|
|
44
|
+
-- SubmitIfValid formId
|
|
45
|
+
-- formData
|
|
46
|
+
-- (isValid formData.fields)
|
|
47
|
+
-- (userMsg
|
|
48
|
+
-- |> Maybe.map
|
|
49
|
+
-- (\toUserMsg ->
|
|
50
|
+
-- toUserMsg { fields = formData.fields }
|
|
51
|
+
-- )
|
|
52
|
+
-- )
|
|
53
|
+
-- )
|
|
54
|
+
--
|
|
55
|
+
--
|
|
56
|
+
--
|
|
57
|
+
--{-| -}
|
|
58
|
+
--fetcherOnSubmit : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
|
|
59
|
+
--fetcherOnSubmit userMsg formId isValid =
|
|
60
|
+
-- FormDecoder.formDataOnSubmit
|
|
61
|
+
-- |> Attr.map
|
|
62
|
+
-- (\formData ->
|
|
63
|
+
-- SubmitFetcher formId
|
|
64
|
+
-- formData
|
|
65
|
+
-- (isValid formData.fields)
|
|
66
|
+
-- (userMsg
|
|
67
|
+
-- |> Maybe.map
|
|
68
|
+
-- (\toUserMsg ->
|
|
69
|
+
-- toUserMsg { fields = formData.fields }
|
|
70
|
+
-- )
|
|
71
|
+
-- )
|
|
72
|
+
-- )
|
|
67
73
|
|
|
68
74
|
|
|
69
75
|
{-| -}
|
|
@@ -74,16 +80,19 @@ map mapFn msg =
|
|
|
74
80
|
UserMsg (mapFn userMsg)
|
|
75
81
|
|
|
76
82
|
Submit info ->
|
|
77
|
-
Submit
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
Submit
|
|
84
|
+
{ valid = info.valid
|
|
85
|
+
, fields = info.fields
|
|
86
|
+
, action = info.action
|
|
87
|
+
, id = info.id
|
|
88
|
+
, msg = Maybe.map mapFn info.msg
|
|
89
|
+
, method = info.method
|
|
90
|
+
, useFetcher = info.useFetcher
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
FormMsg value ->
|
|
94
|
+
FormMsg
|
|
95
|
+
(Form.mapMsg (map mapFn) value)
|
|
87
96
|
|
|
88
97
|
NoOp ->
|
|
89
98
|
NoOp
|