@@ -4,7 +4,7 @@ import Dict
4
4
import Html exposing (..)
5
5
import Html.Attributes exposing (..)
6
6
import Html.Events exposing (onBlur , onFocus , onInput )
7
- import Icons exposing (errorIcon , eye , eyeOff )
7
+ import Icons exposing (deleteIcon , errorIcon , eye , eyeOff )
8
8
import Json.Decode as Decode exposing (Decoder , Value )
9
9
import Json.Encode as Encode
10
10
import Json.Form.Config exposing (TextFieldStyle (..) )
@@ -77,16 +77,19 @@ view model schema isJson isRequired isDisabled path =
77
77
icon =
78
78
if isPassword then
79
79
if model. showPassword then
80
- eyeOff ToggleShowPassword
80
+ ToggleShowPassword |> eyeOff |> Just
81
81
82
82
else
83
- eye ToggleShowPassword
83
+ ToggleShowPassword |> eye |> Just
84
84
85
85
else if hasError then
86
- errorIcon
86
+ errorIcon |> Just
87
+
88
+ else if not isRequired && editedValue /= " " && not actuallyDisabled then
89
+ DeleteProperty path |> deleteIcon |> Just
87
90
88
91
else
89
- text " "
92
+ Nothing
90
93
91
94
baseAttributes =
92
95
[ class " jf-textfield__input"
@@ -172,6 +175,7 @@ view model schema isJson isRequired isDisabled path =
172
175
, ( " jf-textfield--focused" , model. focused |> Maybe . map ( (==) path) |> Maybe . withDefault False )
173
176
, ( " jf-textfield--empty" , editedValue == " " )
174
177
, ( " jf-textfield--invalid" , hasError )
178
+ , ( " jf-textfield--has-icon" , icon /= Nothing )
175
179
, ( " jf-textfield--disabled" , actuallyDisabled )
176
180
, ( " jf-textfield--multiline" , multilineConfig /= Nothing )
177
181
, ( " jf-textfield--json" , isJson )
@@ -221,6 +225,30 @@ viewNumeric model schema isRequired isDisabled path =
221
225
222
226
actuallyDisabled =
223
227
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
+ []
224
252
in
225
253
div
226
254
[ classList
@@ -237,22 +265,13 @@ viewNumeric model schema isRequired isDisabled path =
237
265
, ( " jf-textfield--focused" , isFocused )
238
266
, ( " jf-textfield--empty" , editedValue == " " )
239
267
, ( " jf-textfield--invalid" , hasError )
268
+ , ( " jf-textfield--has-icon" , icon /= Nothing )
240
269
, ( " jf-textfield--disabled" , actuallyDisabled )
241
270
, ( " jf-textfield--hidden" , hidden )
242
271
]
243
272
]
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 " " )
256
275
, label [ class " jf-textfield__label" ] [ schema |> getTitle isRequired |> text ]
257
276
]
258
277
, div [ class " jf-helper-text" ] [ helperText ]
0 commit comments