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 7302f61

Browse files
committed
fix titles for checkboxes and input[type=number]
1 parent 727705b commit 7302f61

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

‎elm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"elm/html": "1.0.0 <= v < 2.0.0",
1818
"elm/json": "1.1.2 <= v < 2.0.0",
1919
"elm/regex": "1.0.0 <= v < 2.0.0",
20+
"elm-community/html-extra": "3.4.0 <= v < 4.0.0",
2021
"elmcraft/core-extra": "2.0.0 <= v < 3.0.0",
2122
"json-tools/json-schema": "1.0.2 <= v < 2.0.0",
2223
"kutyel/elm-form": "1.0.0 <= v < 2.0.0",

‎src/Json/Schema/Form/Fields.elm

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Html.Attributes
1919
, tabindex
2020
, type_
2121
)
22+
import Html.Attributes.Extra as Attr
2223
import Html.Events exposing (preventDefaultOn)
2324
import Html.Keyed
2425
import Json.Decode
@@ -97,24 +98,24 @@ fieldView options path schema type_ form =
9798
select options path schema (getFieldAsString path form)
9899

99100
else
100-
txt options path schema (getFieldAsString path form)
101+
txt options path schema (getFieldAsString path form){ isNumber =True}
101102

102103
NumberType ->
103104
if schema.oneOf /= Nothing || schema.anyOf /= Nothing then
104105
select options path schema (getFieldAsString path form)
105106

106107
else
107-
txt options path schema (getFieldAsString path form)
108+
txt options path schema (getFieldAsString path form){ isNumber =True}
108109

109110
StringType ->
110111
if schema.oneOf /= Nothing || schema.anyOf /= Nothing then
111112
select options path schema (getFieldAsString path form)
112113

113114
else
114-
txt options path schema (getFieldAsString path form)
115+
txt options path schema (getFieldAsString path form){ isNumber =False}
115116

116117
BooleanType ->
117-
checkbox options schema (getFieldAsBool path form)
118+
checkbox options path schema (getFieldAsBool path form)
118119

119120
ArrayType ->
120121
let
@@ -146,8 +147,8 @@ fieldView options path schema type_ form =
146147
div [] []
147148

148149

149-
txt : Options -> Path -> SubSchema -> F.FieldState ErrorValue String -> Html F.Msg
150-
txt options path schema f =
150+
txt : Options -> Path -> SubSchema -> F.FieldState ErrorValue String -> { isNumber : Bool } ->Html F.Msg
151+
txt options path schema f { isNumber }=
151152
let
152153
format : Format
153154
format =
@@ -180,7 +181,8 @@ txt options path schema f =
180181
attributes =
181182
[ classList classes
182183
, id f.path
183-
, placeholder (format.placeholder |> Maybe.withDefault "")
184+
, Attr.attributeIf isNumber <| attribute "type" "number"
185+
, Attr.attributeMaybe placeholder format.placeholder
184186
, case format.autocomplete of
185187
Just "on" ->
186188
autocomplete True
@@ -267,8 +269,8 @@ txt options path schema f =
267269
]
268270

269271

270-
checkbox : Options -> SubSchema -> F.FieldState ErrorValue Bool -> Html F.Msg
271-
checkbox options schema f =
272+
checkbox : Options -> Path->SubSchema -> F.FieldState ErrorValue Bool -> Html F.Msg
273+
checkbox options path schema f =
272274
let
273275
content : List (Html F.Msg)
274276
content =
@@ -280,7 +282,7 @@ checkbox options schema f =
280282
]
281283
, id f.path
282284
]
283-
, text (schema.title |> Maybe.withDefault "")
285+
, fieldTitle schema path |> Maybe.withDefault(text "")
284286
]
285287
]
286288

‎tests/FieldsTest.elm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ singleTypes =
151151
\_ ->
152152
buildSchema
153153
|> withType "integer"
154-
|> isTextField
154+
|> isInputTypeNumber
155155
, describe "oneOf"
156156
[ test "should be a select" <|
157157
\_ ->
@@ -172,7 +172,7 @@ singleTypes =
172172
\_ ->
173173
buildSchema
174174
|> withType "number"
175-
|> isTextField
175+
|> isInputTypeNumber
176176
, describe "oneOf"
177177
[ test "should be a select" <|
178178
\_ ->
@@ -335,6 +335,7 @@ isCheckbox schema =
335335
|> withTitle "Test"
336336
|> Expect.all
337337
[ isField
338+
, hasFieldTitle
338339
, hasFieldDescription
339340
, view
340341
(Expect.all
@@ -377,6 +378,27 @@ isTextField =
377378
]
378379

379380

381+
isInputTypeNumber : SchemaBuilder -> Expectation
382+
isInputTypeNumber =
383+
Expect.all
384+
[ isField
385+
, hasFieldTitle
386+
, hasFieldDescription
387+
, view
388+
(Expect.all
389+
[ Query.find [ tag "input" ]
390+
>> Query.has
391+
[ attribute
392+
(Html.Attributes.attribute
393+
"type"
394+
"number"
395+
)
396+
]
397+
]
398+
)
399+
]
400+
401+
380402
isFieldset : SchemaBuilder -> Expectation
381403
isFieldset schema =
382404
schema

0 commit comments

Comments
(0)

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