Update field status on events.

This commit is contained in:
Dillon Kearns 2022-06-09 09:03:39 -07:00
parent 10111e15a2
commit 5a1555fb2c

View File

@ -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