docassemble icon indicating copy to clipboard operation
docassemble copied to clipboard

DADict.true_values() sorts results in different order than initial order

Open staffanm opened this issue 2 years ago • 1 comments

Given the following interview (where fruits are sorted not alphabetically, but by juiciness)

question: |
  Please tell me what you think.
fields:
  - "Select the fruits you like": likes_fruit
    datatype: checkboxes
    choices:
      - Pears
      - Apples
      - Peaches
      - Plums
---
mandatory: True
question: |
  Summary of your answer
subquestion: |
  You like
  ${ likes_fruit.true_values() }.

If I select pears and apples, the resulting text is "you like apples and pears". I would have expected that the selected values are given in the order that they are specified in the choices list.

If i instead have a subquestion with something like

  You like ${DAList(elements=[x for x in likes_fruit if likes_fruit[x]])}

...then values are in the expected order. Maybe true_values() could have a optional parameter specifying the order of the results?

staffanm avatar May 20 '22 11:05 staffanm

Sure, in the next version I'll add an optional keyword parameter insertion_order that you can set to True if you want the items returned in the underlying dict's stored insertion order.

jhpyle avatar May 20 '22 12:05 jhpyle

I am closing this issue because the insertion_order feature was implemented.

jhpyle avatar Aug 13 '22 14:08 jhpyle