Skip to content

Commit

Permalink
Merge pull request #3058 from CSCfi/anssi/fix-pdf-multiselect-rendering
Browse files Browse the repository at this point in the history
Fix pdf rendering multiple values in multiselect field
  • Loading branch information
Macroz committed Oct 11, 2022
2 parents 2b4af9c + 3d1c7f8 commit f326859
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Changes since v2.29
- Don't needlessly complain about the config keys that are passed automatically from system properties and the environment. (#2935)
- Application warning and error links were not functioning correctly for attachment fields. This is now fixed. (#2955)
- DUO fields are no longer editable in the UI when application is not in editable state. (#2997)
- Multiselect field is now correctly rendered in application pdf again. More than one selected value resulted in empty field value. (#3059)

## v2.29 "Länsisatamankatu" 2022-09-12

Expand Down
9 changes: 7 additions & 2 deletions src/clj/rems/db/test_data_helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [clj-time.core :as time]
[medley.core :refer [assoc-some]]
[clojure.test :refer :all]
[clojure.string]
[rems.api.services.catalogue :as catalogue]
[rems.api.services.category :as category]
[rems.api.services.command :as command]
Expand Down Expand Up @@ -216,7 +217,7 @@
:actor actor
:time (or time (time/now))})

(defn fill-form! [{:keys [application-id actor field-value optional-fields attachment] :as command}]
(defn fill-form! [{:keys [application-id actor field-value optional-fields attachment multiselect] :as command}]
(let [app (applications/get-application-for-user actor application-id)]
(command! (assoc (base-command command)
:type :application.command/save-draft
Expand All @@ -236,7 +237,11 @@
:table (repeat 2 (for [column (:field/columns field)]
{:column (:key column) :value field-value}))
:attachment (str attachment)
(:option :multiselect) (:key (first (:field/options field)))
:option (:key (first (:field/options field)))
:multiselect (or multiselect
(->> (:field/options field)
(map :key)
(clojure.string/join " ")))
(or field-value "x"))})))))

(defn fill-duo-codes! [{:keys [application-id actor duos] :as command}]
Expand Down
11 changes: 10 additions & 1 deletion src/clj/rems/pdf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@
(defn- field-value [filenames field]
(let [value (:field/value field)]
(case (:field/type field)
(:option :multiselect)
:option
(localized (-> (build-index {:keys [:key] :value-fn :label}
(:field/options field))
(get value)))

:multiselect
(let [options (build-index {:keys [:key] :value-fn :label}
(:field/options field))
values (form/parse-multiselect-values value)]
(->> (sort values) ; parse returns set which can be in random order
(map (partial get options))
(map localized)
(str/join ", ")))

:attachment
(if (empty? value)
value
Expand Down
2 changes: 1 addition & 1 deletion test/clj/rems/test_pdf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@
[[:paragraph pdf/field-heading-style "Conditional field. Shown only if first option is selected above."]
[:paragraph "pdf test"]]
[[:paragraph pdf/field-heading-style "Multi-select list"]
[:paragraph "First option"]]
[:paragraph "First option, Second option, Third option"]]
[[:paragraph pdf/field-heading-style "Table"]
[:paragraph
[:table {:header ["First" "Second"]}
Expand Down

0 comments on commit f326859

Please sign in to comment.