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

@ -22,6 +22,7 @@ import Api.Model.ItemFieldValue exposing (ItemFieldValue)
import Comp.CustomFieldInput import Comp.CustomFieldInput
import Comp.FixedDropdown import Comp.FixedDropdown
import Data.CustomFieldChange exposing (CustomFieldChange(..)) import Data.CustomFieldChange exposing (CustomFieldChange(..))
import Data.CustomFieldType
import Data.DropdownStyle as DS import Data.DropdownStyle as DS
import Data.Flags exposing (Flags) import Data.Flags exposing (Flags)
import Dict exposing (Dict) import Dict exposing (Dict)
@ -217,8 +218,16 @@ update1 forSearch flags msg model =
cmd_ = cmd_ =
Cmd.map (CustomFieldInputMsg f) fc 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 in
UpdateResult model_ cmd_ NoFieldChange UpdateResult model_ cmd_ change
RemoveField f -> RemoveField f ->
let let

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