Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the display value of a selected codelist entry in the datamodel #1104

Closed
2 tasks
Tracked by #1660 ...
RonnyB71 opened this issue Apr 18, 2023 · 6 comments · Fixed by #1879
Closed
2 tasks
Tracked by #1660 ...

Store the display value of a selected codelist entry in the datamodel #1104

RonnyB71 opened this issue Apr 18, 2023 · 6 comments · Fixed by #1879
Assignees
Labels
kind/user-story Used for issues that describes functionality for our users. org/ssb Issues relevant for Statistisk sentralbyrå.

Comments

@RonnyB71
Copy link
Member

RonnyB71 commented Apr 18, 2023

Description

Codelists are connected to checkboxes, radiobuttons and dropdowns and consist of a key/value pair. Today only the key is persisted when these fields are connected to the data model.There are however several cases where you would like to store the actual text displayed to the user as well in order to reference that field later in the form. This can be achieved today by doing an additional lookkup on DataProcessWrite, but this requires C# and extra complexity just for storing an already known value.

Additional Information

This should not be solved using a | (or other symbol) and store both values in the same field as this only pushes complexity further down the processing chain.

Blocked by: #1175

Possible solutions:

  1. Map the text value to data model
  2. Allow components as data source for a text resource as this would allow for formatted values in texts.

Tasks

No response

Acceptance Criterias

  • Ability to configure a separate field for storing the text value of a selected codelist entry
  • Selected text value is stored in the selected field
@RonnyB71 RonnyB71 added kind/user-story Used for issues that describes functionality for our users. org/ssb Issues relevant for Statistisk sentralbyrå. labels Apr 18, 2023
@ivarne
Copy link
Member

ivarne commented Apr 18, 2023

One solution might be to have something like

{
    "type": "RadioButtons",
    "dataModelBindings":{
        "simpleBinding": "normal.store.of.key",
        "valueBinding": "additional.store.of.translated.tekst.shown"
    }
}

@olemartinorg
Copy link
Contributor

olemartinorg commented Apr 24, 2023

I agree with @ivarne, but I'll add that it feels a bit redundant to include the word binding everywhere. A simpleBinding seems to always mean that the value is bound as a string value, so in a way I think it should just be called string, or at the very least just simple, but it's easy to see in hindsight. For this new binding, I think we should use label as a key, as that's the term we use in option lists.

So:

{
    "type": "RadioButtons",
    "dataModelBindings":{
        "simpleBinding": "normal.store.of.key",
        "label": "additional.store.of.translated.tekst.shown"
    }
}

It might also be worth noting that this solution is (in a way) already in place in the List component. There, it is expected that you choose one of the cells from the table, store that cell value in the data model, and for the Summary display value, you choose one of the bindings to display.

@bjosttveit
Copy link
Member

Possibly related, if the use case is to display the label (instead of the value) elsewhere: #1105

This is the same as solution 2.

@olemartinorg
Copy link
Contributor

Yup, I think we should have both! The expression for looking up the display value of a component would be nice, but at the same time that display value might not be very machine readable. I think part of the point of having this in the data model is that it can be extracted and processed in backend code (or on the receiving end when the form is submitted).

One more thing Ronny reminded me about today: This probably requires us to map to more list-like structures in the data model. For a checkbox group, comma-separated option values might work, but option labels are far more likely to contain commas (as they are meant to be human readable). Making this work smoothly might require us to know more about the data model and store the display values properly (see #990).

@bjosttveit
Copy link
Member

Solution 2 is kind of possible now since #1341 . You can now get the formatted value of any component including the label of a selected code list using the new displayValue expression. So if the use-case is simply to display the formatted value of a code list in a text it can be achieved using:

{
  "textResourceBindings": {
    "title": ["concat", ["text", "selectedColor"], ": ", ["displayValue", "radio-button-component"]]
  }
}

Which would result in something like

Farge valgt: Blå

@olemartinorg olemartinorg added the fe-v4 Issues to be solved before v4 goes gold label Sep 25, 2023
@RonnyB71 RonnyB71 mentioned this issue Nov 22, 2023
Closed
@RonnyB71 RonnyB71 removed the fe-v4 Issues to be solved before v4 goes gold label Feb 12, 2024
@adamhaeger adamhaeger self-assigned this Feb 22, 2024
@adamhaeger
Copy link
Contributor

Putting this on blocked as I might have discovered a bug in the PATCH while working on this.

If you add an subtract a value in a list, and this ends up in the PATCH request we end up with this payload:

Image

As you can see, value 4 was first deleted, but then we try to insert a value in the same position.

We end up with this response from backend:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/user-story Used for issues that describes functionality for our users. org/ssb Issues relevant for Statistisk sentralbyrå.
Projects
Status: Done
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants