mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 23:12:22 +03:00
Update field status on events.
This commit is contained in:
parent
10111e15a2
commit
5a1555fb2c
@ -129,13 +129,13 @@ updateForm fieldEvent formState =
|
||||
in
|
||||
(case fieldEvent.event of
|
||||
InputEvent newValue ->
|
||||
{ previousValue | value = newValue |> Debug.log fieldEvent.name }
|
||||
{ previousValue | value = newValue }
|
||||
|
||||
FocusEvent ->
|
||||
previousValue
|
||||
{ previousValue | status = previousValue.status |> increaseStatusTo Focused }
|
||||
|
||||
BlurEvent ->
|
||||
previousValue
|
||||
{ previousValue | status = previousValue.status |> increaseStatusTo Blurred }
|
||||
)
|
||||
|> Just
|
||||
)
|
||||
@ -160,3 +160,28 @@ type FieldStatus
|
||||
| Focused
|
||||
| Changed
|
||||
| Blurred
|
||||
|
||||
|
||||
increaseStatusTo : FieldStatus -> FieldStatus -> FieldStatus
|
||||
increaseStatusTo increaseTo currentStatus =
|
||||
if statusRank increaseTo > statusRank currentStatus then
|
||||
increaseTo
|
||||
|
||||
else
|
||||
currentStatus
|
||||
|
||||
|
||||
statusRank : FieldStatus -> Int
|
||||
statusRank status =
|
||||
case status of
|
||||
NotVisited ->
|
||||
0
|
||||
|
||||
Focused ->
|
||||
1
|
||||
|
||||
Changed ->
|
||||
2
|
||||
|
||||
Blurred ->
|
||||
3
|
||||
|
Loading…
Reference in New Issue
Block a user