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 de272f5

Browse files
committed
Add support for placeholder on text inputs.
1 parent 80d8807 commit de272f5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

‎example/Main.elm‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ schema =
153153
, ( "color"
154154
, buildSchema
155155
|> withTitle "Color"
156-
|> withDescription "Please enter either red, gren or blue."
156+
|> withExamples
157+
[ string "Please enter either red, gren or blue."
158+
]
157159
|> withNullableType "string"
158160
|> withEnum
159161
[ string "red"

‎src/Schema/Form.elm‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,32 @@ fieldView options path schema type_ form =
127127

128128
txt : Options -> SubSchema -> F.FieldState ValidationError String -> Html F.Msg
129129
txt options schema f =
130-
field options
131-
schema
132-
f
133-
[ fieldTitle schema
134-
, Input.textInput f
130+
let
131+
attributes =
135132
[ classList
136133
[ ( "form-control", True )
137134
, ( "is-invalid", f.liveError /= Nothing )
138135
]
139136
, id f.path
140137
]
138+
139+
placeholders =
140+
case schema.examples of
141+
Just examples ->
142+
examples
143+
|> List.map (Json.Decode.decodeValue Json.Decode.string)
144+
|> List.map Result.toMaybe
145+
|> List.filterMap identity
146+
|> List.map placeholder
147+
148+
Nothing ->
149+
[]
150+
in
151+
field options
152+
schema
153+
f
154+
[ fieldTitle schema
155+
, Input.textInput f (attributes ++ placeholders)
141156
]
142157

143158

0 commit comments

Comments
(0)

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