Merge pull request #867 from eikek/fix/842-bool-custom-field

Fix/842 bool custom field
This commit is contained in:
mergify[bot] 2021-06-10 19:19:26 +00:00 committed by GitHub
commit 3e11414e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 11 deletions

View File

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

View File

@ -22,6 +22,7 @@ import Api.Model.ItemFieldValue exposing (ItemFieldValue)
import Comp.CustomFieldInput
import Comp.FixedDropdown
import Data.CustomFieldChange exposing (CustomFieldChange(..))
import Data.CustomFieldType
import Data.DropdownStyle as DS
import Data.Flags exposing (Flags)
import Dict exposing (Dict)
@ -217,8 +218,16 @@ update1 forSearch flags msg model =
cmd_ =
Cmd.map (CustomFieldInputMsg f) fc
change =
case Data.CustomFieldType.fromString f.ftype of
Just Data.CustomFieldType.Boolean ->
FieldValueChange f (Util.CustomField.boolValue False)
_ ->
NoFieldChange
in
UpdateResult model_ cmd_ NoFieldChange
UpdateResult model_ cmd_ change
RemoveField f ->
let

View File

@ -1,5 +1,6 @@
module Util.CustomField exposing
( nameOrLabel
( boolValue
, nameOrLabel
, renderValue
, renderValue2
)
@ -12,6 +13,17 @@ import Html.Attributes exposing (..)
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 fv =
Maybe.withDefault fv.name fv.label