# Sort Smart Field checkbox options

**URL:** <https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603>\
**Category:** Help me!\
**Created:** [October 25, 2021, 7:49am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603 "2021-10-25T07:49:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 25, 2021, 7:49am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/1 "2021-10-25T07:49:02Z")

</div>

Hey, I have a smart field defined with the following method:

```javascript
{
	field: `${tagTypeName}_tag`,
	type: ['String'],
	get: (product) => displayTagNames(product, tagType),
	set: setTags,
}

```

The edit form looks like this, because I selected the “checkboxes” edit widget.

 ![Screen Shot 2021-10-25 at 9.47.52 AM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/13a954191b4e478dcf66393ae897005a86297322.png)

## Expected behavior

I expect there to be a way to sort the checkbox options

## System info

```javascript
  "dependencies": {
    "body-parser": "1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17.1",
    "express-jwt": "6.0.0",
    "forest-cli": "^2.3.5",
    "forest-express-sequelize": "^8.0.0",
    "morgan": "1.9.1",
    "pg": "~8.2.2",
    "require-all": "^3.0.0",
    "sequelize": "~5.15.1"
  }

```

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 25, 2021, 7:57am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/2 "2021-10-25T07:57:53Z")

</div>

Hey @cooki23 👋

There is currently no way to achieve such behavior from a UI perspective, so I’m pushing this to our product board.  
However, I’m guessing the current order to related to the way you send back the `displayTagNames` values?

Let me know

---

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 25, 2021, 8:43am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/3 "2021-10-25T08:43:24Z")

</div>

Hey @anon39848301 , the `displayTagNames` function definition is the following. If I am not mistaken the return value is sorted. But the display in the edit form is not ?

```javascript
async function displayTagNames(product, tagType) {
	let productTags = await product.getTags({order: [['name', 'ASC']]})
	return productTags.filter(tag => tag.tagType === Number(tagType)).map(tag => tag.name)
}

```

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 25, 2021, 8:48am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/4 "2021-10-25T08:48:21Z")

</div>

That was only a guess from my end, sadly (This is not that common to have so much checkboxes I guess 🙂 , and I did not have a setup on my end to check).

I’ll need to investigate a bit to check where these values are sorted, in case a workaround is possible, but in any case, your feedback has been pushed to our product board 👍

I’ll let you know if I find something useful to share

---

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 25, 2021, 8:49am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/5 "2021-10-25T08:49:15Z")

</div>

Thank you @anon39848301 , I’ll be awaiting your response 🙂

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 25, 2021, 9:03am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/6 "2021-10-25T09:03:39Z")

</div>

Do you have any configuration on your checkboxes widget I can rely on?

EDIT: I’m able to reproduce a similar behavior with any configuration on the checkbox widget.  
However, defining a smart api endpoint makes me able to sort or manually handle the order of the item display on the UI.

Let me know if that helps 🙏

---

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 26, 2021, 10:05am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/7 "2021-10-26T10:05:05Z")

</div>

Hey @anon39848301 , thanks for your reply. Unfortunately I don’t understand what you’re telling me.

Could you please elaborate a bit more ? a code example would help 🙂

Thanks,  
Camille

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 26, 2021, 10:24am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/8 "2021-10-26T10:24:03Z")

</div>

@cooki23,

I’m speaking about checkboxes configuration:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/31e99645bee605fd74e8a60c9e4382954aca7ae2.png)  
I’ve tested this one, and the order of the checkboxes is actually the one specified in the list.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/53b630e8c5cd392305c09466dac4023851509a2e.png)  
For this one, there is no real way to re-order the checkboxes, sadly (Pushed to our product board)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2eede93a3e3e22fae9a07b0edb2ae2c24b717965.png)  
This is the one I was suggesting in my previous message.

By declaring a smart endpoint for your checkboxes allowed values, you should be able to re-order them as you liked.

Let me know if I’m clearer 🙂

---

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 26, 2021, 10:35am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/9 "2021-10-26T10:35:45Z")

</div>

@anon39848301 great thanks, I’m actually using a “Dynamic” & “Simple” configuration, so I guess there is no current way to order the result ☹

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 26, 2021, 10:41am UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/10 "2021-10-26T10:41:35Z")

</div>

Indeed ☹

As stated, I already push this as a feature request suggestion, that’s the best I can do.

However, my suggestion to go with and API endpoint based solution instead (Dynamic \> Smart) should not be super code-heavy in your case.

I’m marking the thread as resolved since I pushed your suggestion, but if you need help or want to give Dynamic \> Smart a shot, feel free to open a new thread, and I’ll be happy to help if you want to try this solution 🙂

---

<div class="post-metadata">

**Author:** ![cooki23](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cooki23](https://community.forestadmin.com/u/cooki23)\
**Post date:** [October 26, 2021, 12:34pm UTC](https://community.forestadmin.com/t/sort-smart-field-checkbox-options/3603/11 "2021-10-26T12:34:00Z")

</div>

Thanks @anon39848301 I’ll reach out again if need be, have a nice day 🙂
