Use a single place to create values for bool custom fields

This commit is contained in:
eikek 2021-06-10 01:29:46 +02:00
parent 29cfa035f4
commit 7ec0668f03
3 changed files with 17 additions and 11 deletions

View File

@ -24,6 +24,7 @@ import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput) import Html.Events exposing (onClick, onInput)
import Messages.Comp.CustomFieldInput exposing (Texts) import Messages.Comp.CustomFieldInput exposing (Texts)
import Styles as S import Styles as S
import Util.CustomField
import Util.Maybe import Util.Maybe
@ -267,18 +268,11 @@ update1 forSearch msg model =
( ToggleBool, BoolField b ) -> ( ToggleBool, BoolField b ) ->
let let
notb =
not b
model_ = model_ =
{ model | fieldModel = BoolField notb } { model | fieldModel = BoolField (not b) }
value = value =
if notb then Util.CustomField.boolValue (not b)
"true"
else
"false"
in in
UpdateResult model_ Cmd.none (Value value) UpdateResult model_ Cmd.none (Value value)

View File

@ -222,7 +222,7 @@ update1 forSearch flags msg model =
change = change =
case Data.CustomFieldType.fromString f.ftype of case Data.CustomFieldType.fromString f.ftype of
Just Data.CustomFieldType.Boolean -> Just Data.CustomFieldType.Boolean ->
FieldValueChange f "false" FieldValueChange f (Util.CustomField.boolValue False)
_ -> _ ->
NoFieldChange NoFieldChange

View File

@ -1,5 +1,6 @@
module Util.CustomField exposing module Util.CustomField exposing
( nameOrLabel ( boolValue
, nameOrLabel
, renderValue , renderValue
, renderValue2 , renderValue2
) )
@ -12,6 +13,17 @@ import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
{-| This is how the server wants the value to a bool custom field
-}
boolValue : Bool -> String
boolValue b =
if b then
"true"
else
"false"
nameOrLabel : { r | name : String, label : Maybe String } -> String nameOrLabel : { r | name : String, label : Maybe String } -> String
nameOrLabel fv = nameOrLabel fv =
Maybe.withDefault fv.name fv.label Maybe.withDefault fv.name fv.label