Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 984e556

Browse files
committed
Show validation errors after editing only
1 parent 34cebb6 commit 984e556

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

‎bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Anatoliy <mail@anatoliy.in>"
77
],
88
"license": "GNU GENERAL PUBLIC LICENSE v3",
9-
"homepage": "https://github.com/1602/json-form",
9+
"homepage": "https://github.com/json-tools/json-form",
1010
"ignore": [
1111
"**/.*",
1212
"node_modules",

‎src/Json/Form.elm

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ update msg model =
359359
FocusInput focused ->
360360
( { model
361361
| focused = focused
362-
, beingEdited = touch focused model.focused model.beingEdited
362+
, beingFocused = touch focused model.focused model.beingFocused
363363
}
364364
, Cmd.none
365365
)
@@ -368,7 +368,7 @@ update msg model =
368368
FocusTextInput focused ->
369369
( { model
370370
| focused = Just focused
371-
, beingEdited = touch (Just focused) model.focused model.beingEdited
371+
, beingFocused = touch (Just focused) model.focused model.beingFocused
372372
}
373373
, focused |> String.join "_" |> Browser.Dom.focus |> Task.attempt (\_ -> NoOp)
374374
)
@@ -379,7 +379,7 @@ update msg model =
379379
Nothing ->
380380
if isNumber then
381381
editValue
382-
{ model | beingEdited = touch focused model.focused model.beingEdited, focused = Nothing }
382+
{ model | beingFocused = touch focused model.focused model.beingFocused, focused = Nothing }
383383
(model.focused |> Maybe.withDefault [])
384384
(case model.editedJson |> String.toFloat of
385385
Just num ->
@@ -390,7 +390,7 @@ update msg model =
390390
)
391391

392392
else
393-
( { model | beingEdited = touch focused model.focused model.beingEdited, focused = Nothing }
393+
( { model | beingFocused = touch focused model.focused model.beingFocused, focused = Nothing }
394394
, Cmd.none
395395
)
396396
|> withExMsg None
@@ -481,13 +481,13 @@ update msg model =
481481

482482

483483
touch : Maybe Path -> Maybe Path -> List Path -> List Path
484-
touch path focused beingEdited =
484+
touch path focused beingWhat =
485485
if path == Nothing then
486-
beingEdited
486+
beingWhat
487487
|> (::) (focused |> Maybe.withDefault [])
488488

489489
else
490-
beingEdited
490+
beingWhat
491491

492492

493493
editValue : Model -> Path -> JsonValue -> ( ( Model, Cmd Msg ), ExternalMsg )
@@ -516,6 +516,7 @@ editValue model path val =
516516
|> decodeValue JsonValue.decoder
517517
|> Result.toMaybe
518518
, errors = Dict.empty
519+
, beingEdited = touch Nothing (Just path) model.beingEdited
519520
}
520521
, Cmd.none
521522
)
@@ -529,6 +530,7 @@ editValue model path val =
529530
( { model
530531
| value = Just updatedJsonValue
531532
, errors = errors
533+
, beingEdited = touch Nothing (Just path) model.beingEdited
532534
}
533535
, Cmd.none
534536
)
@@ -612,6 +614,7 @@ init config schema v =
612614
, value = value
613615
, errors = errors
614616
, beingEdited = []
617+
, beingFocused = []
615618
, editedJson = ""
616619
, showPassword = False
617620
, fieldHeights = Dict.empty

‎src/Json/Form/Definitions.elm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type alias Model =
2020
, value : Maybe JsonValue
2121
, errors : Dict Path (List String)
2222
, beingEdited : List Path
23+
, beingFocused : List Path
2324
, editedJson : String
2425
, showPassword : Bool
2526
, fieldHeights : Dict Path Float

‎src/Json/Form/Helper.elm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ view model schema path =
1515
|> Dict.get path
1616

1717
hasError =
18-
errors /= Nothing && List.member path model.beingEdited
18+
errors
19+
/= Nothing
20+
&& List.member path model.beingEdited
21+
&& List.member path model.beingFocused
1922
in
2023
( hasError
2124
, if hasError then

‎src/Json/Form/TextField.elm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,12 @@ view model schema isJson isRequired isDisabled path =
205205
, ( "jf-textfield--multiline", multilineConfig /= Nothing )
206206
, ( "jf-textfield--json", isJson )
207207
]
208-
208+
]
209209
-- , onFocus <| FocusTextInput path
210210
-- , Html.Attributes.tabindex -1
211-
]
212-
[ textInput
211+
[ label [ class "jf-textfield__label"][ schema |> getTitle isRequired |> text ]
212+
, textInput
213213
, icon |> Maybe.withDefault (text "")
214-
, label [ class "jf-textfield__label" ] [ schema |> getTitle isRequired |> text ]
215214
]
216215
, div [ class "jf-helper-text" ] [ helperText ]
217216
, case enum of
@@ -310,9 +309,9 @@ viewNumeric model schema isRequired isDisabled path =
310309
, ( "jf-textfield--hidden", hidden )
311310
]
312311
]
313-
[ numericInput
312+
[ label [ class "jf-textfield__label" ] [ schema |> getTitle isRequired |> text ]
313+
, numericInput
314314
, icon |> Maybe.withDefault (text "")
315-
, label [ class "jf-textfield__label" ] [ schema |> getTitle isRequired |> text ]
316315
]
317316
, div [ class "jf-helper-text" ] [ helperText ]
318317
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /