Sort Smart Field checkbox options

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

	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.

Expected behavior

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

System info

  "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"

Hey @cooki23 :wave:

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

1 Like

Hey @jeffladiray , 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 ?

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

That was only a guess from my end, sadly (This is not that common to have so much checkboxes I guess :slight_smile: , 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 :+1:

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

Thank you @jeffladiray , I’ll be awaiting your response :slight_smile:

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 :pray:

Hey @jeffladiray , 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 :slight_smile:



I’m speaking about checkboxes configuration:

I’ve tested this one, and the order of the checkboxes is actually the one specified in the list.

For this one, there is no real way to re-order the checkboxes, sadly (Pushed to our product board)

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 :slight_smile:

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

Indeed :frowning:

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 :slight_smile:

1 Like

Thanks @jeffladiray I’ll reach out again if need be, have a nice day :slight_smile:

1 Like