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 6adf220

Browse files
committed
Add ability to erase value
1 parent b28c1eb commit 6adf220

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

‎src/Json/Form/TextField.elm

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Dict
44
import Html exposing (..)
55
import Html.Attributes exposing (..)
66
import Html.Events exposing (onBlur, onFocus, onInput)
7-
import Icons exposing (errorIcon, eye, eyeOff)
7+
import Icons exposing (deleteIcon, errorIcon, eye, eyeOff)
88
import Json.Decode as Decode exposing (Decoder, Value)
99
import Json.Encode as Encode
1010
import Json.Form.Config exposing (TextFieldStyle(..))
@@ -77,16 +77,19 @@ view model schema isJson isRequired isDisabled path =
7777
icon =
7878
if isPassword then
7979
if model.showPassword then
80-
eyeOff ToggleShowPassword
80+
ToggleShowPassword|>eyeOff |>Just
8181

8282
else
83-
eye ToggleShowPassword
83+
ToggleShowPassword|>eye |>Just
8484

8585
else if hasError then
86-
errorIcon
86+
errorIcon |> Just
87+
88+
else if not isRequired && editedValue /= "" && not actuallyDisabled then
89+
DeleteProperty path |> deleteIcon |> Just
8790

8891
else
89-
text ""
92+
Nothing
9093

9194
baseAttributes =
9295
[ class "jf-textfield__input"
@@ -172,6 +175,7 @@ view model schema isJson isRequired isDisabled path =
172175
, ( "jf-textfield--focused", model.focused |> Maybe.map ((==) path) |> Maybe.withDefault False )
173176
, ( "jf-textfield--empty", editedValue == "" )
174177
, ( "jf-textfield--invalid", hasError )
178+
, ( "jf-textfield--has-icon", icon /= Nothing )
175179
, ( "jf-textfield--disabled", actuallyDisabled )
176180
, ( "jf-textfield--multiline", multilineConfig /= Nothing )
177181
, ( "jf-textfield--json", isJson )
@@ -221,6 +225,30 @@ viewNumeric model schema isRequired isDisabled path =
221225

222226
actuallyDisabled =
223227
isDisabled || disabled
228+
229+
icon =
230+
if hasError then
231+
errorIcon |> Just
232+
233+
else if not isRequired && editedValue /= "" && not actuallyDisabled then
234+
DeleteProperty path |> deleteIcon |> Just
235+
236+
else
237+
Nothing
238+
239+
numericInput =
240+
input
241+
[ class "jf-textfield__input"
242+
, onFocus <| FocusFragileInput True (Just path)
243+
, onBlur <| FocusFragileInput True Nothing
244+
, onInput <| EditNumber
245+
, Html.Attributes.id id
246+
, Html.Attributes.name id
247+
, value <| editedValue
248+
, type_ "number"
249+
, Html.Attributes.disabled actuallyDisabled
250+
]
251+
[]
224252
in
225253
div
226254
[ classList
@@ -237,22 +265,13 @@ viewNumeric model schema isRequired isDisabled path =
237265
, ( "jf-textfield--focused", isFocused )
238266
, ( "jf-textfield--empty", editedValue == "" )
239267
, ( "jf-textfield--invalid", hasError )
268+
, ( "jf-textfield--has-icon", icon /= Nothing )
240269
, ( "jf-textfield--disabled", actuallyDisabled )
241270
, ( "jf-textfield--hidden", hidden )
242271
]
243272
]
244-
[ input
245-
[ class "jf-textfield__input"
246-
, onFocus <| FocusFragileInput True (Just path)
247-
, onBlur <| FocusFragileInput True Nothing
248-
, onInput <| EditNumber
249-
, Html.Attributes.id id
250-
, Html.Attributes.name id
251-
, value <| editedValue
252-
, type_ "number"
253-
, Html.Attributes.disabled actuallyDisabled
254-
]
255-
[]
273+
[ numericInput
274+
, icon |> Maybe.withDefault (text "")
256275
, label [ class "jf-textfield__label" ] [ schema |> getTitle isRequired |> text ]
257276
]
258277
, div [ class "jf-helper-text" ] [ helperText ]

0 commit comments

Comments
(0)

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