Answers.Body: <p>It's an extra plugin but SuperSort would do the job - <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">https://github.com/TopShelfCraft/SuperSort</a></p>
  
  <p>Edit - couldn't make it work in one go, but this works:
  <code>
  {% set results = [] %}
  {% for field in submission %}
    {% set results = results | merge([{'handle': field.handle, 'value': submission[field.handle].value}]) %}
  {% endfor %}
  {% set sortedResults = results | supersort('sortAs', '{value}', SORT_NUMERIC) %}
  </code></p>
  
  <p>Not the most elegant, let me know if you find a better solution!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T09:42:47.697Z
Answers.Text: Thanks, Seb - it isn't that clear how we would use the plugin in this scenario though.
Answers.UserDisplayName: Dan Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T10:50:10.787Z
Answers.Text: Would the following be correct?
  
  {% for field in submission | supersort('sortAs', 'submission[field.handle].value', SORT_NUMERIC) %}
Answers.UserDisplayName: Dan Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T20:35:35.013Z
Answers.Text: yes though I believe you need to use the twig delimiters, and use object (untested):
  
  `{% set sortedSubmission = submission | supersort('sortAs', '{{ submission[object.handle].value }}', SORT_NUMERIC) %}`
Answers.UserDisplayName: Seb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T21:06:58.197Z
Answers.Text: actually this doesn't work, just edited my answer above with another solution
Answers.UserDisplayName: Seb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-24T08:04:51.293Z
Answers.Text: Thanks - I get an "Array to string conversion" error when adding this line: {% set sortedResults = results | supersort('sortAs', '{value}', SORT_NUMERIC) %}
Answers.UserDisplayName: Dan Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-24T08:38:56.517Z
Answers.Text: can you paste the whole code excerpt?
Answers.UserDisplayName: Seb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-24T08:42:14.373Z
Answers.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/99032/discussion-between-dan-lee-and-seb).
Answers.UserDisplayName: Dan Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T09:01:00.170Z
Answers.LastActivityDate: 2019-09-24T07:15:24.923Z
Answers.LastEditDate: 2019-09-24T07:15:24.923Z
Answers.UserDisplayName: Seb
Body: <p>I’m looping through some text fields on the form results page and need to order the numerical output from low to high.</p>
  
  <p><strong>How would I do this using twig?</strong></p>
  
  <pre><code>{% for field in submission %}
    {% submission[field.handle].value %}
  {% endfor %}
  </code></pre>
  
  <p>Note: I am using the Freeform Plugin. They have informed me that I would need to create a custom filter but before I do that wanted to see if there was a better way to do this.</p>
  
Tags: <forloop><loop>
Title: Ordering Looped Results by Field's Numerical Value
ThreadText: # Ordering Looped Results by Field's Numerical Value
  
  (Asked by: username_0 on 2019-09-23)
  
  I’m looping through some text fields on the form results page and need to order the numerical output from low to high.
  
  **How would I do this using twig?**
  
  ```
  {% for field in submission %}
    {% submission[field.handle].value %}
  {% endfor %}
  
  ```
  
  Note: I am using the Freeform Plugin. They have informed me that I would need to create a custom filter but before I do that wanted to see if there was a better way to do this.
  
  **Tags:** forloop, loop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-23. Score: 1 | Accepted answer
  
  It's an extra plugin but SuperSort would do the job - <https://github.com/TopShelfCraft/SuperSort>
  
  Edit - couldn't make it work in one go, but this works:
  `{% set results = [] %}
  {% for field in submission %}
  {% set results = results | merge([{'handle': field.handle, 'value': submission[field.handle].value}]) %}
  {% endfor %}
  {% set sortedResults = results | supersort('sortAs', '{value}', SORT_NUMERIC) %}`
  
  Not the most elegant, let me know if you find a better solution!
  
  > **Comments:**
  > **username_0**: Thanks, Seb - it isn't that clear how we would use the plugin in this scenario though.  
  > **username_0**: Would the following be correct?  {% for field in submission | supersort('sortAs', 'submission[field.handle].value', SORT_NUMERIC) %}  
  > **username_1**: yes though I believe you need to use the twig delimiters, and use object (untested):  `{% set sortedSubmission = submission | supersort('sortAs', '{{ submission[object.handle].value }}', SORT_NUMERIC) %}`  
  > **username_1**: actually this doesn't work, just edited my answer above with another solution  
  > **username_0**: Thanks - I get an "Array to string conversion" error when adding this line: {% set sortedResults = results | supersort('sortAs', '{value}', SORT_NUMERIC) %}  
  > **username_1**: can you paste the whole code excerpt?  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/99032/discussion-between-username_0-and-seb).  
  
  ---
  
  