elm-pages 3.0.0-beta.32 → 3.0.0-beta.34
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 +10 -78
- 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/compatibility-key.js +2 -2
- package/generator/src/render.js +1 -0
- package/generator/src/request-cache.js +20 -6
- package/generator/static-code/elm-pages.js +10 -0
- package/package.json +3 -3
- package/src/BackendTask/Http.elm +8 -2
- 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 +1 -5
- 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/RequestsAndPending.elm +31 -3
- 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
package/src/Form/Field.elm
DELETED
|
@@ -1,729 +0,0 @@
|
|
|
1
|
-
module Form.Field exposing
|
|
2
|
-
( text, checkbox, int, float
|
|
3
|
-
, select, range, OutsideRange(..)
|
|
4
|
-
, date, time, TimeOfDay
|
|
5
|
-
, Field(..), FieldInfo, exactValue
|
|
6
|
-
, required, withClientValidation, withInitialValue, withOptionalInitialValue, map
|
|
7
|
-
, email, password, search, telephone, url, textarea
|
|
8
|
-
, withMax, withMin, withStep, withMinLength, withMaxLength
|
|
9
|
-
, No, Yes
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
{-|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Base Fields
|
|
16
|
-
|
|
17
|
-
@docs text, checkbox, int, float
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## Multiple Choice Fields
|
|
21
|
-
|
|
22
|
-
@docs select, range, OutsideRange
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## Date/Time Fields
|
|
26
|
-
|
|
27
|
-
@docs date, time, TimeOfDay
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Other
|
|
31
|
-
|
|
32
|
-
@docs Field, FieldInfo, exactValue
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
## Field Configuration
|
|
36
|
-
|
|
37
|
-
@docs required, withClientValidation, withInitialValue, withOptionalInitialValue, map
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
## Text Field Display Options
|
|
41
|
-
|
|
42
|
-
@docs email, password, search, telephone, url, textarea
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
## Numeric Field Options
|
|
46
|
-
|
|
47
|
-
@docs withMax, withMin, withStep, withMinLength, withMaxLength
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## Phantom Options
|
|
51
|
-
|
|
52
|
-
@docs No, Yes
|
|
53
|
-
|
|
54
|
-
-}
|
|
55
|
-
|
|
56
|
-
import Date exposing (Date)
|
|
57
|
-
import Dict exposing (Dict)
|
|
58
|
-
import Form.FieldView as FieldView exposing (Input, Options(..))
|
|
59
|
-
import Form.Value
|
|
60
|
-
import Json.Encode as Encode
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
{-| -}
|
|
64
|
-
type Field error parsed data kind constraints
|
|
65
|
-
= Field (FieldInfo error parsed data) kind
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{-| -}
|
|
69
|
-
type alias FieldInfo error parsed data =
|
|
70
|
-
{ initialValue : Maybe (data -> Maybe String)
|
|
71
|
-
, decode : Maybe String -> ( Maybe parsed, List error )
|
|
72
|
-
, properties : List ( String, Encode.Value )
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
{-| -}
|
|
77
|
-
type Yes
|
|
78
|
-
= Yes Never
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
{-| -}
|
|
82
|
-
type No
|
|
83
|
-
= No Never
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| -}
|
|
87
|
-
required :
|
|
88
|
-
error
|
|
89
|
-
->
|
|
90
|
-
Field
|
|
91
|
-
error
|
|
92
|
-
(Maybe parsed)
|
|
93
|
-
data
|
|
94
|
-
kind
|
|
95
|
-
{ constraints
|
|
96
|
-
| required : ()
|
|
97
|
-
, wasMapped : No
|
|
98
|
-
}
|
|
99
|
-
-> Field error parsed data kind { constraints | wasMapped : No }
|
|
100
|
-
required missingError (Field field kind) =
|
|
101
|
-
Field
|
|
102
|
-
{ initialValue = field.initialValue
|
|
103
|
-
, decode =
|
|
104
|
-
\rawValue ->
|
|
105
|
-
let
|
|
106
|
-
( parsed, allErrors ) =
|
|
107
|
-
field.decode rawValue
|
|
108
|
-
|
|
109
|
-
isEmpty : Bool
|
|
110
|
-
isEmpty =
|
|
111
|
-
rawValue == Just "" || rawValue == Nothing
|
|
112
|
-
in
|
|
113
|
-
( parsed |> Maybe.andThen identity
|
|
114
|
-
, if isEmpty then
|
|
115
|
-
missingError :: allErrors
|
|
116
|
-
|
|
117
|
-
else
|
|
118
|
-
allErrors
|
|
119
|
-
)
|
|
120
|
-
, properties = field.properties
|
|
121
|
-
}
|
|
122
|
-
kind
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
{-| -}
|
|
126
|
-
text :
|
|
127
|
-
Field
|
|
128
|
-
error
|
|
129
|
-
(Maybe String)
|
|
130
|
-
data
|
|
131
|
-
Input
|
|
132
|
-
{ required : ()
|
|
133
|
-
, plainText : ()
|
|
134
|
-
, wasMapped : No
|
|
135
|
-
, initial : String
|
|
136
|
-
, minlength : ()
|
|
137
|
-
, maxlength : ()
|
|
138
|
-
}
|
|
139
|
-
text =
|
|
140
|
-
Field
|
|
141
|
-
{ initialValue = Nothing
|
|
142
|
-
, decode =
|
|
143
|
-
\rawValue ->
|
|
144
|
-
( if rawValue == Just "" then
|
|
145
|
-
Just Nothing
|
|
146
|
-
|
|
147
|
-
else
|
|
148
|
-
Just rawValue
|
|
149
|
-
, []
|
|
150
|
-
)
|
|
151
|
-
, properties = []
|
|
152
|
-
}
|
|
153
|
-
(FieldView.Input FieldView.Text)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
{-| -}
|
|
157
|
-
date :
|
|
158
|
-
{ invalid : String -> error }
|
|
159
|
-
->
|
|
160
|
-
Field
|
|
161
|
-
error
|
|
162
|
-
(Maybe Date)
|
|
163
|
-
data
|
|
164
|
-
Input
|
|
165
|
-
{ min : Date
|
|
166
|
-
, max : Date
|
|
167
|
-
, required : ()
|
|
168
|
-
, wasMapped : No
|
|
169
|
-
, initial : Date
|
|
170
|
-
}
|
|
171
|
-
date toError =
|
|
172
|
-
Field
|
|
173
|
-
{ initialValue = Nothing
|
|
174
|
-
, decode =
|
|
175
|
-
\rawString ->
|
|
176
|
-
if (rawString |> Maybe.withDefault "") == "" then
|
|
177
|
-
( Just Nothing, [] )
|
|
178
|
-
|
|
179
|
-
else
|
|
180
|
-
case
|
|
181
|
-
rawString
|
|
182
|
-
|> Maybe.withDefault ""
|
|
183
|
-
|> Date.fromIsoString
|
|
184
|
-
|> Result.mapError (\_ -> toError.invalid (rawString |> Maybe.withDefault ""))
|
|
185
|
-
of
|
|
186
|
-
Ok parsedDate ->
|
|
187
|
-
( Just (Just parsedDate), [] )
|
|
188
|
-
|
|
189
|
-
Err error ->
|
|
190
|
-
( Nothing, [ error ] )
|
|
191
|
-
, properties = []
|
|
192
|
-
}
|
|
193
|
-
(FieldView.Input FieldView.Date)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
{-| -}
|
|
197
|
-
type alias TimeOfDay =
|
|
198
|
-
{ hours : Int
|
|
199
|
-
, minutes : Int
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
{-| <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time>
|
|
204
|
-
-}
|
|
205
|
-
time :
|
|
206
|
-
{ invalid : String -> error }
|
|
207
|
-
->
|
|
208
|
-
Field
|
|
209
|
-
error
|
|
210
|
-
(Maybe TimeOfDay)
|
|
211
|
-
data
|
|
212
|
-
Input
|
|
213
|
-
{ -- TODO support min/max
|
|
214
|
-
--min : ???,
|
|
215
|
-
--, max : ???,
|
|
216
|
-
required : ()
|
|
217
|
-
, wasMapped : No
|
|
218
|
-
}
|
|
219
|
-
time toError =
|
|
220
|
-
Field
|
|
221
|
-
{ initialValue = Nothing
|
|
222
|
-
, decode =
|
|
223
|
-
\rawString ->
|
|
224
|
-
if (rawString |> Maybe.withDefault "") == "" then
|
|
225
|
-
( Just Nothing, [] )
|
|
226
|
-
|
|
227
|
-
else
|
|
228
|
-
case
|
|
229
|
-
rawString
|
|
230
|
-
|> Maybe.withDefault ""
|
|
231
|
-
|> parseTimeOfDay
|
|
232
|
-
|> Result.mapError (\_ -> toError.invalid (rawString |> Maybe.withDefault ""))
|
|
233
|
-
of
|
|
234
|
-
Ok parsedDate ->
|
|
235
|
-
( Just (Just parsedDate), [] )
|
|
236
|
-
|
|
237
|
-
Err error ->
|
|
238
|
-
( Nothing, [ error ] )
|
|
239
|
-
, properties = []
|
|
240
|
-
}
|
|
241
|
-
(FieldView.Input FieldView.Time)
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
parseTimeOfDay : String -> Result () { hours : Int, minutes : Int }
|
|
245
|
-
parseTimeOfDay rawTimeOfDay =
|
|
246
|
-
case rawTimeOfDay |> String.split ":" |> List.map String.toInt of
|
|
247
|
-
[ Just hours, Just minutes ] ->
|
|
248
|
-
Ok
|
|
249
|
-
{ hours = hours
|
|
250
|
-
, minutes = minutes
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
_ ->
|
|
254
|
-
Err ()
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
{-| -}
|
|
258
|
-
select :
|
|
259
|
-
List ( String, option )
|
|
260
|
-
-> (String -> error)
|
|
261
|
-
->
|
|
262
|
-
Field
|
|
263
|
-
error
|
|
264
|
-
(Maybe option)
|
|
265
|
-
data
|
|
266
|
-
(Options option)
|
|
267
|
-
{ required : ()
|
|
268
|
-
, wasMapped : No
|
|
269
|
-
}
|
|
270
|
-
select optionsMapping invalidError =
|
|
271
|
-
let
|
|
272
|
-
dict : Dict String option
|
|
273
|
-
dict =
|
|
274
|
-
Dict.fromList optionsMapping
|
|
275
|
-
|
|
276
|
-
fromString : String -> Maybe option
|
|
277
|
-
fromString string =
|
|
278
|
-
Dict.get string dict
|
|
279
|
-
in
|
|
280
|
-
Field
|
|
281
|
-
{ initialValue = Nothing
|
|
282
|
-
, decode =
|
|
283
|
-
\rawValue ->
|
|
284
|
-
case rawValue of
|
|
285
|
-
Nothing ->
|
|
286
|
-
( Just Nothing, [] )
|
|
287
|
-
|
|
288
|
-
Just "" ->
|
|
289
|
-
( Just Nothing, [] )
|
|
290
|
-
|
|
291
|
-
Just justValue ->
|
|
292
|
-
let
|
|
293
|
-
parsed : Maybe option
|
|
294
|
-
parsed =
|
|
295
|
-
fromString justValue
|
|
296
|
-
in
|
|
297
|
-
case parsed of
|
|
298
|
-
Just okParsed ->
|
|
299
|
-
( Just (Just okParsed)
|
|
300
|
-
, []
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
Nothing ->
|
|
304
|
-
( Just Nothing
|
|
305
|
-
, [ invalidError justValue
|
|
306
|
-
]
|
|
307
|
-
)
|
|
308
|
-
, properties = []
|
|
309
|
-
}
|
|
310
|
-
(Options fromString (optionsMapping |> List.map Tuple.first))
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
{-| -}
|
|
314
|
-
exactValue :
|
|
315
|
-
String
|
|
316
|
-
-> error
|
|
317
|
-
->
|
|
318
|
-
Field
|
|
319
|
-
error
|
|
320
|
-
String
|
|
321
|
-
data
|
|
322
|
-
Input
|
|
323
|
-
{ required : ()
|
|
324
|
-
, plainText : ()
|
|
325
|
-
, wasMapped : No
|
|
326
|
-
, initial : String
|
|
327
|
-
}
|
|
328
|
-
exactValue initialValue error =
|
|
329
|
-
Field
|
|
330
|
-
{ initialValue = Just (\_ -> Just initialValue)
|
|
331
|
-
, decode =
|
|
332
|
-
\rawValue ->
|
|
333
|
-
if rawValue == Just initialValue then
|
|
334
|
-
( rawValue, [] )
|
|
335
|
-
|
|
336
|
-
else
|
|
337
|
-
( rawValue, [ error ] )
|
|
338
|
-
, properties = []
|
|
339
|
-
}
|
|
340
|
-
(FieldView.Input FieldView.Text)
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
{-| -}
|
|
344
|
-
checkbox :
|
|
345
|
-
Field
|
|
346
|
-
error
|
|
347
|
-
Bool
|
|
348
|
-
data
|
|
349
|
-
Input
|
|
350
|
-
{ required : ()
|
|
351
|
-
, initial : Bool
|
|
352
|
-
}
|
|
353
|
-
checkbox =
|
|
354
|
-
Field
|
|
355
|
-
{ initialValue = Nothing
|
|
356
|
-
, decode =
|
|
357
|
-
\rawString ->
|
|
358
|
-
( (rawString == Just "on")
|
|
359
|
-
|> Just
|
|
360
|
-
, []
|
|
361
|
-
)
|
|
362
|
-
, properties = []
|
|
363
|
-
}
|
|
364
|
-
(FieldView.Input FieldView.Checkbox)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
{-| -}
|
|
368
|
-
int :
|
|
369
|
-
{ invalid : String -> error }
|
|
370
|
-
->
|
|
371
|
-
Field
|
|
372
|
-
error
|
|
373
|
-
(Maybe Int)
|
|
374
|
-
data
|
|
375
|
-
Input
|
|
376
|
-
{ min : Int
|
|
377
|
-
, max : Int
|
|
378
|
-
, required : ()
|
|
379
|
-
, wasMapped : No
|
|
380
|
-
, step : Int
|
|
381
|
-
, initial : Int
|
|
382
|
-
}
|
|
383
|
-
int toError =
|
|
384
|
-
Field
|
|
385
|
-
{ initialValue = Nothing
|
|
386
|
-
, decode =
|
|
387
|
-
\rawString ->
|
|
388
|
-
case rawString of
|
|
389
|
-
Nothing ->
|
|
390
|
-
( Just Nothing, [] )
|
|
391
|
-
|
|
392
|
-
Just "" ->
|
|
393
|
-
( Just Nothing, [] )
|
|
394
|
-
|
|
395
|
-
Just string ->
|
|
396
|
-
case string |> String.toInt of
|
|
397
|
-
Just parsedInt ->
|
|
398
|
-
( Just (Just parsedInt), [] )
|
|
399
|
-
|
|
400
|
-
Nothing ->
|
|
401
|
-
( Nothing, [ toError.invalid string ] )
|
|
402
|
-
, properties = []
|
|
403
|
-
}
|
|
404
|
-
(FieldView.Input FieldView.Number)
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
{-| -}
|
|
408
|
-
float :
|
|
409
|
-
{ invalid : String -> error }
|
|
410
|
-
->
|
|
411
|
-
Field
|
|
412
|
-
error
|
|
413
|
-
(Maybe Float)
|
|
414
|
-
data
|
|
415
|
-
Input
|
|
416
|
-
{ min : Float
|
|
417
|
-
, max : Float
|
|
418
|
-
, required : ()
|
|
419
|
-
, wasMapped : No
|
|
420
|
-
, initial : Float
|
|
421
|
-
}
|
|
422
|
-
float toError =
|
|
423
|
-
Field
|
|
424
|
-
{ initialValue = Nothing
|
|
425
|
-
, decode =
|
|
426
|
-
\rawString ->
|
|
427
|
-
case rawString of
|
|
428
|
-
Nothing ->
|
|
429
|
-
( Just Nothing, [] )
|
|
430
|
-
|
|
431
|
-
Just "" ->
|
|
432
|
-
( Just Nothing, [] )
|
|
433
|
-
|
|
434
|
-
Just string ->
|
|
435
|
-
case string |> String.toFloat of
|
|
436
|
-
Just parsedFloat ->
|
|
437
|
-
( Just (Just parsedFloat), [] )
|
|
438
|
-
|
|
439
|
-
Nothing ->
|
|
440
|
-
( Nothing, [ toError.invalid string ] )
|
|
441
|
-
, properties = []
|
|
442
|
-
}
|
|
443
|
-
(FieldView.Input FieldView.Number)
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
{-| -}
|
|
447
|
-
telephone :
|
|
448
|
-
Field error parsed data Input { constraints | plainText : () }
|
|
449
|
-
-> Field error parsed data Input constraints
|
|
450
|
-
telephone (Field field _) =
|
|
451
|
-
Field field
|
|
452
|
-
(FieldView.Input FieldView.Tel)
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
{-| -}
|
|
456
|
-
search :
|
|
457
|
-
Field error parsed data Input { constraints | plainText : () }
|
|
458
|
-
-> Field error parsed data Input constraints
|
|
459
|
-
search (Field field _) =
|
|
460
|
-
Field field
|
|
461
|
-
(FieldView.Input FieldView.Search)
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
{-| -}
|
|
465
|
-
password :
|
|
466
|
-
Field error parsed data Input { constraints | plainText : () }
|
|
467
|
-
-> Field error parsed data Input constraints
|
|
468
|
-
password (Field field _) =
|
|
469
|
-
Field field
|
|
470
|
-
(FieldView.Input FieldView.Password)
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
{-| -}
|
|
474
|
-
email :
|
|
475
|
-
Field error parsed data Input { constraints | plainText : () }
|
|
476
|
-
-> Field error parsed data Input constraints
|
|
477
|
-
email (Field field _) =
|
|
478
|
-
Field field
|
|
479
|
-
(FieldView.Input FieldView.Email)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
{-| -}
|
|
483
|
-
url :
|
|
484
|
-
Field error parsed data Input { constraints | plainText : () }
|
|
485
|
-
-> Field error parsed data Input constraints
|
|
486
|
-
url (Field field _) =
|
|
487
|
-
Field field
|
|
488
|
-
(FieldView.Input FieldView.Url)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
{-| -}
|
|
492
|
-
textarea :
|
|
493
|
-
{ rows : Maybe Int, cols : Maybe Int }
|
|
494
|
-
-> Field error parsed data Input { constraints | plainText : () }
|
|
495
|
-
-> Field error parsed data Input constraints
|
|
496
|
-
textarea options (Field field _) =
|
|
497
|
-
Field field (FieldView.Input (FieldView.Textarea options))
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
{-| -}
|
|
501
|
-
type OutsideRange
|
|
502
|
-
= AboveRange
|
|
503
|
-
| BelowRange
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
{-| -}
|
|
507
|
-
range :
|
|
508
|
-
{ min : Form.Value.Value valueType
|
|
509
|
-
, max : Form.Value.Value valueType
|
|
510
|
-
, initial : data -> Form.Value.Value valueType
|
|
511
|
-
, missing : error
|
|
512
|
-
, invalid : OutsideRange -> error
|
|
513
|
-
}
|
|
514
|
-
->
|
|
515
|
-
Field
|
|
516
|
-
error
|
|
517
|
-
(Maybe valueType)
|
|
518
|
-
data
|
|
519
|
-
kind
|
|
520
|
-
{ constraints
|
|
521
|
-
| required : ()
|
|
522
|
-
, initial : valueType
|
|
523
|
-
, min : valueType
|
|
524
|
-
, max : valueType
|
|
525
|
-
, wasMapped : No
|
|
526
|
-
}
|
|
527
|
-
->
|
|
528
|
-
Field
|
|
529
|
-
error
|
|
530
|
-
valueType
|
|
531
|
-
data
|
|
532
|
-
Input
|
|
533
|
-
{ constraints | wasMapped : No }
|
|
534
|
-
range info field =
|
|
535
|
-
field
|
|
536
|
-
|> required info.missing
|
|
537
|
-
|> withMin info.min (info.invalid BelowRange)
|
|
538
|
-
|> withMax info.max (info.invalid AboveRange)
|
|
539
|
-
|> (\(Field innerField _) -> Field { innerField | initialValue = Just (info.initial >> Form.Value.toString >> Just) } (FieldView.Input FieldView.Range))
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
{-| -}
|
|
543
|
-
map : (parsed -> mapped) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
|
|
544
|
-
map mapFn field_ =
|
|
545
|
-
withClientValidation
|
|
546
|
-
(\value -> ( Just (mapFn value), [] ))
|
|
547
|
-
field_
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
{-| -}
|
|
551
|
-
withClientValidation : (parsed -> ( Maybe mapped, List error )) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
|
|
552
|
-
withClientValidation mapFn (Field field kind) =
|
|
553
|
-
Field
|
|
554
|
-
{ initialValue = field.initialValue
|
|
555
|
-
, decode =
|
|
556
|
-
\value ->
|
|
557
|
-
value
|
|
558
|
-
|> field.decode
|
|
559
|
-
|> (\( maybeValue, errors ) ->
|
|
560
|
-
case maybeValue of
|
|
561
|
-
Nothing ->
|
|
562
|
-
( Nothing, errors )
|
|
563
|
-
|
|
564
|
-
Just okValue ->
|
|
565
|
-
okValue
|
|
566
|
-
|> mapFn
|
|
567
|
-
|> Tuple.mapSecond ((++) errors)
|
|
568
|
-
)
|
|
569
|
-
, properties = field.properties
|
|
570
|
-
}
|
|
571
|
-
kind
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
{-| -}
|
|
575
|
-
withInitialValue : (data -> Form.Value.Value valueType) -> Field error value data kind { constraints | initial : valueType } -> Field error value data kind constraints
|
|
576
|
-
withInitialValue toInitialValue (Field field kind) =
|
|
577
|
-
Field
|
|
578
|
-
{ field
|
|
579
|
-
| initialValue =
|
|
580
|
-
Just (toInitialValue >> Form.Value.toString >> Just)
|
|
581
|
-
}
|
|
582
|
-
kind
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
{-| -}
|
|
586
|
-
withOptionalInitialValue : (data -> Maybe (Form.Value.Value valueType)) -> Field error value data kind { constraints | initial : valueType } -> Field error value data kind constraints
|
|
587
|
-
withOptionalInitialValue toInitialValue (Field field kind) =
|
|
588
|
-
Field
|
|
589
|
-
{ field
|
|
590
|
-
| initialValue =
|
|
591
|
-
Just (toInitialValue >> Maybe.map Form.Value.toString)
|
|
592
|
-
}
|
|
593
|
-
kind
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
-- Input Properties
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
{-| -}
|
|
601
|
-
withMin : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | min : valueType } -> Field error parsed data kind constraints
|
|
602
|
-
withMin min error (Field field kind) =
|
|
603
|
-
Field
|
|
604
|
-
{ initialValue = field.initialValue
|
|
605
|
-
, decode =
|
|
606
|
-
\value ->
|
|
607
|
-
value
|
|
608
|
-
|> field.decode
|
|
609
|
-
|> (\( maybeValue, errors ) ->
|
|
610
|
-
case maybeValue of
|
|
611
|
-
Nothing ->
|
|
612
|
-
( Nothing, errors )
|
|
613
|
-
|
|
614
|
-
Just okValue ->
|
|
615
|
-
if isEmptyValue value then
|
|
616
|
-
( Just okValue, errors )
|
|
617
|
-
|
|
618
|
-
else
|
|
619
|
-
case Form.Value.compare (value |> Maybe.withDefault "") min of
|
|
620
|
-
LT ->
|
|
621
|
-
( Just okValue, error :: errors )
|
|
622
|
-
|
|
623
|
-
_ ->
|
|
624
|
-
( Just okValue, errors )
|
|
625
|
-
)
|
|
626
|
-
, properties = ( "min", Encode.string (Form.Value.toString min) ) :: field.properties
|
|
627
|
-
}
|
|
628
|
-
kind
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
{-| -}
|
|
632
|
-
withMinLength : Int -> error -> Field error parsed data kind { constraints | minlength : () } -> Field error parsed data kind constraints
|
|
633
|
-
withMinLength minLength error (Field field kind) =
|
|
634
|
-
Field
|
|
635
|
-
{ initialValue = field.initialValue
|
|
636
|
-
, decode =
|
|
637
|
-
\value ->
|
|
638
|
-
value
|
|
639
|
-
|> field.decode
|
|
640
|
-
|> (\( maybeValue, errors ) ->
|
|
641
|
-
case maybeValue of
|
|
642
|
-
Nothing ->
|
|
643
|
-
( Nothing, errors )
|
|
644
|
-
|
|
645
|
-
Just okValue ->
|
|
646
|
-
if (value |> Maybe.withDefault "" |> String.length) >= minLength then
|
|
647
|
-
( Just okValue, errors )
|
|
648
|
-
|
|
649
|
-
else
|
|
650
|
-
( Just okValue, error :: errors )
|
|
651
|
-
)
|
|
652
|
-
, properties = ( "minlength", Encode.string (String.fromInt minLength) ) :: field.properties
|
|
653
|
-
}
|
|
654
|
-
kind
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
{-| -}
|
|
658
|
-
withMaxLength : Int -> error -> Field error parsed data kind { constraints | maxlength : () } -> Field error parsed data kind constraints
|
|
659
|
-
withMaxLength maxLength error (Field field kind) =
|
|
660
|
-
Field
|
|
661
|
-
{ initialValue = field.initialValue
|
|
662
|
-
, decode =
|
|
663
|
-
\value ->
|
|
664
|
-
value
|
|
665
|
-
|> field.decode
|
|
666
|
-
|> (\( maybeValue, errors ) ->
|
|
667
|
-
case maybeValue of
|
|
668
|
-
Nothing ->
|
|
669
|
-
( Nothing, errors )
|
|
670
|
-
|
|
671
|
-
Just okValue ->
|
|
672
|
-
if (value |> Maybe.withDefault "" |> String.length) <= maxLength then
|
|
673
|
-
( Just okValue, errors )
|
|
674
|
-
|
|
675
|
-
else
|
|
676
|
-
( Just okValue, error :: errors )
|
|
677
|
-
)
|
|
678
|
-
, properties = ( "maxlength", Encode.string (String.fromInt maxLength) ) :: field.properties
|
|
679
|
-
}
|
|
680
|
-
kind
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
isEmptyValue : Maybe String -> Bool
|
|
684
|
-
isEmptyValue value =
|
|
685
|
-
(value |> Maybe.withDefault "") == ""
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
{-| -}
|
|
689
|
-
withMax : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | max : valueType } -> Field error parsed data kind constraints
|
|
690
|
-
withMax max error (Field field kind) =
|
|
691
|
-
Field
|
|
692
|
-
{ initialValue = field.initialValue
|
|
693
|
-
, decode =
|
|
694
|
-
\value ->
|
|
695
|
-
value
|
|
696
|
-
|> field.decode
|
|
697
|
-
|> (\( maybeValue, errors ) ->
|
|
698
|
-
case maybeValue of
|
|
699
|
-
Nothing ->
|
|
700
|
-
( Nothing, errors )
|
|
701
|
-
|
|
702
|
-
Just okValue ->
|
|
703
|
-
if isEmptyValue value then
|
|
704
|
-
( Just okValue, errors )
|
|
705
|
-
|
|
706
|
-
else
|
|
707
|
-
case Form.Value.compare (value |> Maybe.withDefault "") max of
|
|
708
|
-
GT ->
|
|
709
|
-
( Just okValue, error :: errors )
|
|
710
|
-
|
|
711
|
-
_ ->
|
|
712
|
-
( Just okValue, errors )
|
|
713
|
-
)
|
|
714
|
-
, properties = ( "max", Encode.string (Form.Value.toString max) ) :: field.properties
|
|
715
|
-
}
|
|
716
|
-
kind
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
{-| -}
|
|
720
|
-
withStep : Form.Value.Value valueType -> Field msg error value view { constraints | step : valueType } -> Field msg error value view constraints
|
|
721
|
-
withStep max field =
|
|
722
|
-
withStringProperty ( "step", Form.Value.toString max ) field
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
withStringProperty : ( String, String ) -> Field error parsed data kind constraints1 -> Field error parsed data kind constraints2
|
|
726
|
-
withStringProperty ( key, value ) (Field field kind) =
|
|
727
|
-
Field
|
|
728
|
-
{ field | properties = ( key, Encode.string value ) :: field.properties }
|
|
729
|
-
kind
|