From 29cfa035f4a30e5ce918fb2d1a147459fa366655 Mon Sep 17 00:00:00 2001 From: eikek Date: Thu, 10 Jun 2021 01:26:21 +0200 Subject: [PATCH 1/2] Add boolean custom field immediately with value false The time the user selects this field it should be pushed to the server, because the initial value of "false" is a correct value. All other fields require the user to type something first. --- .../src/main/elm/Comp/CustomFieldMultiInput.elm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm index 5fd04608..1635c31e 100644 --- a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm +++ b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm @@ -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 "false" + + _ -> + NoFieldChange in - UpdateResult model_ cmd_ NoFieldChange + UpdateResult model_ cmd_ change RemoveField f -> let From 7ec0668f031f1647ad99cc5ad0c078386dcc1c8d Mon Sep 17 00:00:00 2001 From: eikek Date: Thu, 10 Jun 2021 01:29:46 +0200 Subject: [PATCH 2/2] Use a single place to create values for bool custom fields --- .../webapp/src/main/elm/Comp/CustomFieldInput.elm | 12 +++--------- .../src/main/elm/Comp/CustomFieldMultiInput.elm | 2 +- modules/webapp/src/main/elm/Util/CustomField.elm | 14 +++++++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm b/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm index 5183ac00..d524e72a 100644 --- a/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm +++ b/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm @@ -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) diff --git a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm index 1635c31e..bb2f6f94 100644 --- a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm +++ b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm @@ -222,7 +222,7 @@ update1 forSearch flags msg model = change = case Data.CustomFieldType.fromString f.ftype of Just Data.CustomFieldType.Boolean -> - FieldValueChange f "false" + FieldValueChange f (Util.CustomField.boolValue False) _ -> NoFieldChange diff --git a/modules/webapp/src/main/elm/Util/CustomField.elm b/modules/webapp/src/main/elm/Util/CustomField.elm index 761e4407..80b75a6d 100644 --- a/modules/webapp/src/main/elm/Util/CustomField.elm +++ b/modules/webapp/src/main/elm/Util/CustomField.elm @@ -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