Checkbox on Smart field

Expected behavior

I can set the Select Edit Widget of my smart field to be Checkbox

Actual behavior

Can do Radio Buttons but not Checkbox

Context

{
“name”: “foxxbee-admin”,
“version”: “0.0.1”,
“private”: true,
“scripts”: {
“start”: “node ./server.js”
},
“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”
}
}

Hi @cooki23,

Can you please share the model definition of this smart field?
Checkbox is selected by default for Boolean datatypes.

Regards

Hey @Sliman_Medini I don’t understand what you mean by model definition for the smart field.
Perhaps you mean the code that’s responsible for creating it ? In that case you can find it below:


const productTagsMap = {
	0: "STYLE",
	1: "COLOR",
	2: "MATERIAL",
	3: "CATEGORY",
	4: "PRODUCT_TYPE",
	5: "ROOM",
	6: "FORM",
	7: "OTHER"
}

const tagTypeFields = getTagTypeFields()

collection('products', {
	actions: [],
	fields: [...tagTypeFields],
	segments: [],
});

function getTagTypeFields() {
	const tagTypes = getTagTypes()
	return tagTypes.map(tagType => {
		let tagTypeName = productTagsMap[tagType]
		return {
			field: `${tagTypeName}_tag`,
			type: 'String',
			get: (product) => displayTagNames(product, tagType),
			set: async (product, tagName) => {
				const productBeforeUpdate = await models.products.findOne({ where: { id: product.id }});
				const updatedTag = await models.tags.findOne({ where: { name: tagName }});
				await productBeforeUpdate.addTag(updatedTag)
				await productBeforeUpdate.save()
				return product
			}
		}
	})
}

async function  displayTagNames(product, tagType) {
	let tagNames = ''
	let productTags = await product.getTags()
	productTags.filter(tag => tag.tagType === Number(tagType)).forEach(tag => {
		tagNames += `${tag.name} | `
	})
	return tagNames.slice(0, tagNames.length - 2);
}

function getTagTypes() {
	return Object.keys(productTagsMap)
}

Radio buttons are supported, but I want to be able to select multiple options…

What is possible as edit widget on the UI depends on the smart field definition.

When using the type ['String'] (instead of ‘String’) then you will be able to select checkboxes as edit widget.

Regards

1 Like